From: kosmirror <kos...@us...> - 2025-05-21 00:12:19
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 49e939a5c0fea9af48357bf250dba14db975fc8a (commit) via 2629afe3291d1bc1e065f0d559cdeace38a23692 (commit) from 7569b6ff7402754c7fa4bca9bc77f43b8005ba82 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 49e939a5c0fea9af48357bf250dba14db975fc8a Author: darc <da...@pr...> Date: Tue May 20 18:40:44 2025 -0500 Update __newlib_lock_acquire_recursive() - Remove unnecessary irq enable/disable from __newlib_lock_acquire_recursive() - Update __newlib_lock_acquire_recursive() to use thd_get_current() commit 2629afe3291d1bc1e065f0d559cdeace38a23692 Author: Falco Girgis <gyr...@gm...> Date: Tue Jan 9 06:51:52 2024 -0600 Implemented Newlib try_lock() functions - __newlib_lock_try_acquire() and __newlib_lock_try_acquire_recursive() were stubbed out to assert and abort due to not being implemented - Implemented both using the new spinlock_trylock() API - Also had to fix their prototypes, since they both should be returning an integer for whether the lock was successfully obtained ----------------------------------------------------------------------- Summary of changes: include/sys/lock.h | 4 +-- kernel/libc/newlib/lock_common.c | 58 +++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/include/sys/lock.h b/include/sys/lock.h index 9b93a959..eec60041 100644 --- a/include/sys/lock.h +++ b/include/sys/lock.h @@ -52,13 +52,13 @@ typedef __newlib_recursive_lock_t _LOCK_RECURSIVE_T; void __newlib_lock_init(__newlib_lock_t*); void __newlib_lock_close(__newlib_lock_t*); void __newlib_lock_acquire(__newlib_lock_t*); -void __newlib_lock_try_acquire(__newlib_lock_t*); +int __newlib_lock_try_acquire(__newlib_lock_t*); void __newlib_lock_release(__newlib_lock_t*); void __newlib_lock_init_recursive(__newlib_recursive_lock_t*); void __newlib_lock_close_recursive(__newlib_recursive_lock_t*); void __newlib_lock_acquire_recursive(__newlib_recursive_lock_t*); -void __newlib_lock_try_acquire_recursive(__newlib_recursive_lock_t*); +int __newlib_lock_try_acquire_recursive(__newlib_recursive_lock_t*); void __newlib_lock_release_recursive(__newlib_recursive_lock_t*); /** \endcond */ diff --git a/kernel/libc/newlib/lock_common.c b/kernel/libc/newlib/lock_common.c index 2105e017..d9e35ccf 100644 --- a/kernel/libc/newlib/lock_common.c +++ b/kernel/libc/newlib/lock_common.c @@ -1,8 +1,9 @@ /* KallistiOS ##version## lock_common.c - Copyright (C)2004 Megan Potter - + Copyright (C) 2004 Megan Potter + Copyright (C) 2024 Falco Girgis + Copyright (C) 2025 Eric Fradella */ #include <assert.h> @@ -11,51 +12,40 @@ #include <kos/thread.h> #include <sys/lock.h> -void __newlib_lock_init(__newlib_lock_t * lock) { +void __newlib_lock_init(__newlib_lock_t *lock) { spinlock_init(lock); } -void __newlib_lock_close(__newlib_lock_t * lock) { +void __newlib_lock_close(__newlib_lock_t *lock) { (void)lock; } -void __newlib_lock_acquire(__newlib_lock_t * lock) { +void __newlib_lock_acquire(__newlib_lock_t *lock) { spinlock_lock(lock); } -void __newlib_lock_try_acquire(__newlib_lock_t * lock) { - (void)lock; - assert_msg(0, "We don't support try_acquire"); +int __newlib_lock_try_acquire(__newlib_lock_t *lock) { + return spinlock_trylock(lock); } -void __newlib_lock_release(__newlib_lock_t * lock) { +void __newlib_lock_release(__newlib_lock_t *lock) { spinlock_unlock(lock); } -void __newlib_lock_init_recursive(__newlib_recursive_lock_t * lock) { +void __newlib_lock_init_recursive(__newlib_recursive_lock_t *lock) { lock->owner = NULL; lock->nest = 0; spinlock_init(&lock->lock); } -void __newlib_lock_close_recursive(__newlib_recursive_lock_t * lock) { +void __newlib_lock_close_recursive(__newlib_recursive_lock_t *lock) { /* Empty */ (void)lock; } -void __newlib_lock_acquire_recursive(__newlib_recursive_lock_t * lock) { - int old; - int iscur; - - // Check to see if we already own it. If so, everything is clear - // to incr nest. Otherwise, we can safely go on to do a normal - // spinlock wait. - old = irq_disable(); - iscur = lock->owner == thd_current; - irq_restore(old); - - if(iscur) { +void __newlib_lock_acquire_recursive(__newlib_recursive_lock_t *lock) { + if(lock->owner == thd_get_current()) { lock->nest++; return; } @@ -64,16 +54,28 @@ void __newlib_lock_acquire_recursive(__newlib_recursive_lock_t * lock) { spinlock_lock(&lock->lock); // We own it now, so it's safe to init the rest of this. - lock->owner = thd_current; + lock->owner = thd_get_current(); lock->nest = 1; } -void __newlib_lock_try_acquire_recursive(__newlib_recursive_lock_t * lock) { - (void)lock; - assert_msg(0, "We don't support try_acquire"); +/* Similar to __newlib_lock_acquire_recursive(), except that it can + fail to obtain the lock. */ +int __newlib_lock_try_acquire_recursive(__newlib_recursive_lock_t *lock) { + if(lock->owner == thd_get_current()) { + lock->nest++; + return 1; + } + + if(spinlock_trylock(&lock->lock)) { + lock->owner = thd_get_current(); + lock->nest = 1; + return 1; + } + + return 0; } -void __newlib_lock_release_recursive(__newlib_recursive_lock_t * lock) { +void __newlib_lock_release_recursive(__newlib_recursive_lock_t *lock) { // Check to see how much we own it. if(lock->nest == 1) { lock->owner = NULL; hooks/post-receive -- A pseudo Operating System for the Dreamcast. |