From: kosmirror <kos...@us...> - 2025-08-05 05:02:15
|
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 7744fa682cf1ead22f6242439dfac52c45ec16ec (commit) via 59e1b7706c53f22fcd3787bd304b33695da20824 (commit) via 844f8babb0a7fe714c15bdc4e63c4dff36e5f2d0 (commit) via da3174025025025e2667dc383ae0e1e27c79014b (commit) via 0965ee1e3e47afd6a4a05c2a30d18fb40d2c3246 (commit) from 3df833497711472b1b0d8546dfcdf5031d3c6fe7 (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 7744fa682cf1ead22f6242439dfac52c45ec16ec Author: QuzarDC <qu...@co...> Date: Fri May 30 03:14:17 2025 -0400 Change mutex type to unsigned int. This allows for simplified invalid type checks. commit 59e1b7706c53f22fcd3787bd304b33695da20824 Author: QuzarDC <qu...@co...> Date: Thu May 29 22:55:11 2025 -0400 Constify params. Where appropriate mark that the passed pointer will not be used to change its data. This is mostly seen in accessors but also with genwait's sleep `obj`. commit 844f8babb0a7fe714c15bdc4e63c4dff36e5f2d0 Author: QuzarDC <qu...@co...> Date: Thu May 22 21:42:58 2025 -0400 Mark function params as non-null for safety and optimization. In each of these there are no tests being done to verify that the input is non-null, and it has already been up to the caller to ensure that before using. commit da3174025025025e2667dc383ae0e1e27c79014b Author: QuzarDC <qu...@co...> Date: Fri May 23 10:16:17 2025 -0400 Remove deprecated dynamic sync primitive creations. These were all deprecated in 2012. Finally being removed. Recursive locks were additionally replaced entirely by recursive type mutexes. commit 0965ee1e3e47afd6a4a05c2a30d18fb40d2c3246 Author: QuzarDC <qu...@co...> Date: Fri May 23 09:10:04 2025 -0400 Correct param name mismatch in sem.c/h For some reason the .h had all params as `sem` while the .c had all but one as `sm`. Shifted them all to `sm` to match the majority within the .c. ----------------------------------------------------------------------- Summary of changes: addons/libpthread/pthread_mutex_init.c | 3 +- include/kos/cond.h | 42 +++----- include/kos/genwait.h | 16 +-- include/kos/mutex.h | 45 +++----- include/kos/recursive_lock.h | 141 -------------------------- include/kos/rwsem.h | 58 ++++------- include/kos/sem.h | 48 +++------ include/kos/thread.h | 1 - kernel/arch/dreamcast/include/arch/spinlock.h | 6 +- kernel/exports.txt | 3 - kernel/thread/Makefile | 2 +- kernel/thread/cond.c | 25 +---- kernel/thread/genwait.c | 30 +++--- kernel/thread/mutex.c | 41 ++------ kernel/thread/recursive_lock.c | 58 ----------- kernel/thread/rwsem.c | 28 +---- kernel/thread/sem.c | 56 +++------- 17 files changed, 112 insertions(+), 491 deletions(-) delete mode 100644 include/kos/recursive_lock.h delete mode 100644 kernel/thread/recursive_lock.c diff --git a/addons/libpthread/pthread_mutex_init.c b/addons/libpthread/pthread_mutex_init.c index fbfa038c..572d3d5b 100644 --- a/addons/libpthread/pthread_mutex_init.c +++ b/addons/libpthread/pthread_mutex_init.c @@ -12,7 +12,8 @@ int pthread_mutex_init(pthread_mutex_t *__RESTRICT mutex, const pthread_mutexattr_t *__RESTRICT attr) { - int type = MUTEX_TYPE_NORMAL, old, rv = 0; + unsigned int type = MUTEX_TYPE_NORMAL; + int old, rv = 0; if(attr) { switch(attr->mtype) { diff --git a/include/kos/cond.h b/include/kos/cond.h index 6cc9cf95..8b954007 100644 --- a/include/kos/cond.h +++ b/include/kos/cond.h @@ -60,48 +60,30 @@ __BEGIN_DECLS */ typedef struct condvar { int dummy; - int dynamic; } condvar_t; /** \brief Initializer for a transient condvar. */ -#define COND_INITIALIZER { 0, 0 } - -/** \brief Allocate a new condition variable. - - This function allocates and initializes a new condition variable for use. - - \deprecated - This function is formally deprecated and should not be used in new code. - Instead you should use either the static initializer or the cond_init() - function. - - \return The created condvar on success. NULL is returned on - failure and errno is set as appropriate. - - \par Error Conditions: - \em ENOMEM - out of memory -*/ -condvar_t *cond_create(void) __depr("Use cond_init or COND_INITIALIZER."); +#define COND_INITIALIZER { 0 } /** \brief Initialize a condition variable. This function initializes a new condition variable for use. \param cv The condition variable to initialize - \retval 0 On success - \retval -1 On error, sets errno as appropriate + \retval 0 On success (no error conditions currently defined) */ -int cond_init(condvar_t *cv); +int cond_init(condvar_t *cv) __nonnull_all; /** \brief Free a condition variable. - This function frees a condition variable, releasing all memory associated - with it (but not with the mutex that is associated with it). This will also - wake all threads waiting on the condition. + This function destroys a condition variable (but not the mutex + that is associated with it). This will also wake all threads waiting + on the condition. + \param cv The condition variable to destroy \retval 0 On success (no error conditions currently defined) */ -int cond_destroy(condvar_t *cv); +int cond_destroy(condvar_t *cv) __nonnull_all; /** \brief Wait on a condition variable. @@ -124,7 +106,7 @@ int cond_destroy(condvar_t *cv); \em EINVAL - the mutex is not initialized or not locked \n \em ENOTRECOVERABLE - the condvar was destroyed while waiting */ -int cond_wait(condvar_t *cv, mutex_t * m); +int cond_wait(condvar_t *cv, mutex_t * m) __nonnull_all; /** \brief Wait on a condition variable with a timeout. @@ -150,7 +132,7 @@ int cond_wait(condvar_t *cv, mutex_t * m); \em EINVAL - the mutex is not initialized or not locked \n \em ENOTRECOVERABLE - the condvar was destroyed while waiting */ -int cond_wait_timed(condvar_t *cv, mutex_t * m, int timeout); +int cond_wait_timed(condvar_t *cv, mutex_t * m, int timeout) __nonnull_all; /** \brief Signal a single thread waiting on the condition variable. @@ -165,7 +147,7 @@ int cond_wait_timed(condvar_t *cv, mutex_t * m, int timeout); \par Error Conditions: \em EINVAL - the condvar was not initialized */ -int cond_signal(condvar_t *cv); +int cond_signal(condvar_t *cv) __nonnull_all; /** \brief Signal all threads waiting on the condition variable. @@ -180,7 +162,7 @@ int cond_signal(condvar_t *cv); \par Error Conditions: \em EINVAL - the condvar was not initialized */ -int cond_broadcast(condvar_t *cv); +int cond_broadcast(condvar_t *cv) __nonnull_all; __END_DECLS diff --git a/include/kos/genwait.h b/include/kos/genwait.h index d2927f6a..0f480a73 100644 --- a/include/kos/genwait.h +++ b/include/kos/genwait.h @@ -47,7 +47,7 @@ __BEGIN_DECLS \par Error Conditions: \em EAGAIN - on timeout */ -int genwait_wait(void * obj, const char * mesg, int timeout, void (*callback)(void *)); +int genwait_wait(void *obj, const char *mesg, int timeout, void (*callback)(void *)); /* Wake up N threads waiting on the given object. If cnt is <=0, then we wake all threads. Returns the number of threads actually woken. */ @@ -67,7 +67,7 @@ int genwait_wait(void * obj, const char * mesg, int timeout, void (*callback)(vo threads. \return The number of threads woken */ -int genwait_wake_cnt(void * obj, int cnt, int err); +int genwait_wake_cnt(const void *obj, int cnt, int err); /** \brief Wake up all threads sleeping on an object. @@ -76,7 +76,7 @@ int genwait_wake_cnt(void * obj, int cnt, int err); \param obj The object to wake threads that are sleeping on it \see genwait_wake_cnt() */ -void genwait_wake_all(void * obj); +void genwait_wake_all(const void *obj); /** \brief Wake up one thread sleeping on an object. @@ -85,7 +85,7 @@ void genwait_wake_all(void * obj); \param obj The object to wake threads that are sleeping on it \see genwait_wake_cnt() */ -void genwait_wake_one(void * obj); +void genwait_wake_one(const void *obj); /** \brief Wake up all threads sleeping on an object, with an error. @@ -95,7 +95,7 @@ void genwait_wake_one(void * obj); \param err The value to set in the threads' errno values \see genwait_wake_cnt() */ -void genwait_wake_all_err(void *obj, int err); +void genwait_wake_all_err(const void *obj, int err); /** \brief Wake up one thread sleeping on an object, with an error. @@ -105,7 +105,7 @@ void genwait_wake_all_err(void *obj, int err); \param err The value to set in the threads' errno values \see genwait_wake_cnt() */ -void genwait_wake_one_err(void *obj, int err); +void genwait_wake_one_err(const void *obj, int err); /** \brief Wake up a specific thread that is sleeping on an object. @@ -113,7 +113,7 @@ void genwait_wake_one_err(void *obj, int err); specified object. \param obj The object to wake the thread from - \param thd The specific thread to wake + \param thd The specific thread to wake (non-null). \param err The errno code to set as the errno value on the woken thread. If this is 0 (EOK), then the thread's errno will not be changed, and the thread will get a @@ -124,7 +124,7 @@ void genwait_wake_one_err(void *obj, int err); \return The number of threads woken, which should be 1 on success. */ -int genwait_wake_thd(void *obj, kthread_t *thd, int err); +int genwait_wake_thd(const void *obj, kthread_t *thd, int err) __nonnull((2)); /** \brief Look for timed out genwait_wait() calls. diff --git a/include/kos/mutex.h b/include/kos/mutex.h index 243b5cc6..3fb273c6 100644 --- a/include/kos/mutex.h +++ b/include/kos/mutex.h @@ -66,8 +66,7 @@ __BEGIN_DECLS \headerfile kos/mutex.h */ typedef struct kos_mutex { - int type; - int dynamic; + unsigned int type; kthread_t *holder; int count; } mutex_t; @@ -84,34 +83,20 @@ typedef struct kos_mutex { #define MUTEX_TYPE_OLDNORMAL 1 /**< \brief Alias for MUTEX_TYPE_NORMAL */ #define MUTEX_TYPE_ERRORCHECK 2 /**< \brief Error-checking mutex type */ #define MUTEX_TYPE_RECURSIVE 3 /**< \brief Recursive mutex type */ +#define MUTEX_TYPE_DESTROYED 4 /**< \brief Mutex that has been destroyed */ /** \brief Default mutex type */ #define MUTEX_TYPE_DEFAULT MUTEX_TYPE_NORMAL /** @} */ /** \brief Initializer for a transient mutex. */ -#define MUTEX_INITIALIZER { MUTEX_TYPE_NORMAL, 0, NULL, 0 } +#define MUTEX_INITIALIZER { MUTEX_TYPE_NORMAL, NULL, 0 } /** \brief Initializer for a transient error-checking mutex. */ -#define ERRORCHECK_MUTEX_INITIALIZER { MUTEX_TYPE_ERRORCHECK, 0, NULL, 0 } +#define ERRORCHECK_MUTEX_INITIALIZER { MUTEX_TYPE_ERRORCHECK, NULL, 0 } /** \brief Initializer for a transient recursive mutex. */ -#define RECURSIVE_MUTEX_INITIALIZER { MUTEX_TYPE_RECURSIVE, 0, NULL, 0 } - -/** \brief Allocate a new mutex. - - \deprecated - This function allocates and initializes a new mutex for use. This function - will always create mutexes of the type MUTEX_TYPE_NORMAL. - - \return The newly created mutex on success, or NULL on - failure (errno will be set as appropriate). - - \note This function is formally deprecated. It should not - be used in any future code, and may be removed in - the future. You should instead use mutex_init(). -*/ -mutex_t *mutex_create(void) __depr("Use mutex_init or an initializer."); +#define RECURSIVE_MUTEX_INITIALIZER { MUTEX_TYPE_RECURSIVE, NULL, 0 } /** \brief Initialize a new mutex. @@ -128,7 +113,7 @@ mutex_t *mutex_create(void) __depr("Use mutex_init or an initializer."); \sa mutex_types */ -int mutex_init(mutex_t *m, int mtype); +int mutex_init(mutex_t *m, unsigned int mtype) __nonnull_all; /** \brief Destroy a mutex. @@ -139,13 +124,15 @@ int mutex_init(mutex_t *m, int mtype); This function can be called on statically initialized as well as dynamically initialized mutexes. + \param m The mutex to destroy + \retval 0 On success \retval -1 On error, errno will be set as appropriate \par Error Conditions: \em EBUSY - the mutex is currently locked */ -int mutex_destroy(mutex_t *m); +int mutex_destroy(mutex_t *m) __nonnull_all; /** \brief Lock a mutex. @@ -165,7 +152,7 @@ int mutex_destroy(mutex_t *m); \em EAGAIN - lock has been acquired too many times (recursive) \n \em EDEADLK - would deadlock (error-checking) */ -int mutex_lock(mutex_t *m); +int mutex_lock(mutex_t *m) __nonnull_all; /** \brief Lock a mutex. @@ -188,7 +175,7 @@ int mutex_lock(mutex_t *m); already locked \n \em EDEADLK - would deadlock (error-checking) */ -int mutex_lock_irqsafe(mutex_t *m); +int mutex_lock_irqsafe(mutex_t *m) __nonnull_all; /** \brief Lock a mutex (with a timeout). @@ -211,7 +198,7 @@ int mutex_lock_irqsafe(mutex_t *m); \em EAGAIN - lock has been acquired too many times (recursive) \n \em EDEADLK - would deadlock (error-checking) */ -int mutex_lock_timed(mutex_t *m, int timeout); +int mutex_lock_timed(mutex_t *m, int timeout) __nonnull_all; /** \brief Check if a mutex is locked. @@ -224,7 +211,7 @@ int mutex_lock_timed(mutex_t *m, int timeout); \retval 0 If the mutex is not currently locked \retval 1 If the mutex is currently locked */ -int mutex_is_locked(mutex_t *m); +int mutex_is_locked(const mutex_t *m) __nonnull_all; /** \brief Attempt to lock a mutex. @@ -244,7 +231,7 @@ int mutex_is_locked(mutex_t *m); \em EAGAIN - lock has been acquired too many times (recursive) \n \em EDEADLK - would deadlock (error-checking) */ -int mutex_trylock(mutex_t *m); +int mutex_trylock(mutex_t *m) __nonnull_all; /** \brief Unlock a mutex. @@ -259,7 +246,7 @@ int mutex_trylock(mutex_t *m); \em EPERM - the current thread does not own the mutex (error-checking or recursive) */ -int mutex_unlock(mutex_t *m); +int mutex_unlock(mutex_t *m) __nonnull_all; /** \brief Unlock a mutex under another thread's authority. @@ -276,7 +263,7 @@ int mutex_unlock(mutex_t *m); \em EPERM - the specified thread does not own the mutex \n \em EACCES - called outside an IRQ handler */ -int mutex_unlock_as_thread(mutex_t *m, kthread_t *thd); +int mutex_unlock_as_thread(mutex_t *m, kthread_t *thd) __nonnull_all; /** \cond */ static inline void __mutex_scoped_cleanup(mutex_t **m) { diff --git a/include/kos/recursive_lock.h b/include/kos/recursive_lock.h deleted file mode 100644 index 83ae7588..00000000 --- a/include/kos/recursive_lock.h +++ /dev/null @@ -1,141 +0,0 @@ -/* KallistiOS ##version## - - include/kos/recursive_lock.h - Copyright (C) 2008, 2010, 2012 Lawrence Sebald - -*/ - -/** \file kos/recursive_lock.h - \brief Definitions for a recursive mutex. - \ingroup kthreads - - This file defines a recursive lock mechanism, similar to a mutex, but that a - single thread can obtain as many times as it wants. A single thread is still - limited to holding the lock at a time, but it can hold it an "unlimited" - number of times (actually limited to INT_MAX, but who's counting). - - \deprecated - These are now just wrappers around the MUTEX_TYPE_RECURSIVE that is now - provided and will be removed at some point in the future. Please update your - code to use that type instead. - - \author Lawrence Sebald -*/ - -#ifndef __KOS_RECURSIVE_LOCK_H -#define __KOS_RECURSIVE_LOCK_H - -#include <kos/cdefs.h> - -__BEGIN_DECLS - -#include <kos/mutex.h> - -/** \brief Recursive lock structure. - - Recursive locks are just a simple wrapper around mutexes at this point. You - should not use this type in any new code. - - \headerfile kos/recursive_lock.h -*/ -typedef mutex_t recursive_lock_t; - -/** \brief Allocate a new recursive lock. - - \deprecated - This function allocates a new recursive lock that is initially not locked. - - \return The created lock, or NULL on failure (errno will be set to ENOMEM to - indicate that the system appears to be out of memory). -*/ -recursive_lock_t *rlock_create(void) __depr("Use mutexes instead."); - -/** \brief Destroy a recursive lock. - - \deprecated - This function cleans up a recursive lock. It is an error to attempt to - destroy a locked recursive lock. - - \param l The recursive lock to destroy. It must be unlocked. -*/ -void rlock_destroy(recursive_lock_t *l) __depr("Use mutexes instead."); - -/** \brief Lock a recursive lock. - - \deprecated - This function attempts to lock the requested lock, and if it cannot it will - block until that is possible. - - \param l The recursive lock to lock. - \retval -1 On error, errno will be set to EPERM if this function is - called inside an interrupt, or EINTR if it is interrupted. - \retval 0 On success. - \sa rlock_trylock - \sa rlock_lock_timed -*/ -int rlock_lock(recursive_lock_t *l) __depr("Use mutexes instead."); - -/** \brief Lock a recursive lock (with a timeout). - - \deprecated - This function attempts to lock the requested lock, and if it cannot it will - block until either it is possible to acquire the lock or timeout - milliseconds have elapsed. - - \param l The recursive lock to lock. - \param timeout The maximum number of milliseconds to wait. 0 is an - unlimited timeout (equivalent to rlock_lock). - \retval -1 On error, errno will be set to EPERM if this function is - called inside an interrupt, EINTR if the function is - interrupted, or EAGAIN if the timeout expires. - \retval 0 On success. - \sa rlock_trylock - \sa rlock_lock_timed -*/ -int rlock_lock_timed(recursive_lock_t *l, int timeout) - __depr("Use mutexes instead."); - -/** \brief Unlock a recursive lock. - - \deprecated - This function releases the lock one time from the current thread. - - \param l The recursive lock to unlock. - \retval -1 On error, errno will be set to EPERM if the lock is not held - by the calling thread. - \retval 0 On success. -*/ -int rlock_unlock(recursive_lock_t *l) __depr("Use mutexes instead."); - -/** \brief Attempt to lock a recursive lock without blocking. - - \deprecated - This function attempts to lock a recursive lock without blocking. This - function, unlike rlock_lock and rlock_lock_timed is safe to call inside an - interrupt. - - \param l The recursive lock to lock. - \retval -1 On error, errno will be set to EWOULDBLOCK if the lock is - currently held by another thread. - \retval 0 On success. - \sa rlock_lock - \sa rlock_lock_timed -*/ -int rlock_trylock(recursive_lock_t *l) __depr("Use mutexes instead."); - -/** \brief Check if a recursive lock is currently held by any thread. - - \deprecated - This function checks whether or not a lock is currently held by any thread, - including the calling thread. Note that this is <b>NOT</b> a safe way to - check if a lock <em>will</em> be held by the time you get around to locking - it. - - \retval TRUE If the lock is held by any thread. - \retval FALSE If the lock is not currently held by any thread. -*/ -int rlock_is_locked(recursive_lock_t *l) __depr("Use mutexes instead."); - -__END_DECLS - -#endif /* !__KOS_RECURSIVE_LOCK_H */ diff --git a/include/kos/rwsem.h b/include/kos/rwsem.h index ad2a05d2..d7612a63 100644 --- a/include/kos/rwsem.h +++ b/include/kos/rwsem.h @@ -41,9 +41,6 @@ __BEGIN_DECLS \headerfile kos/rwsem.h */ typedef struct rw_semaphore { - /** \brief Was this structure created with rwsem_create()? */ - int dynamic; - /** \brief The number of readers that are currently holding the lock. */ int read_count; @@ -55,24 +52,7 @@ typedef struct rw_semaphore { ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |