From: ljsebald <ljs...@us...> - 2023-08-28 04:08:14
|
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 76e04eac072c41936ed4ce088a1903ff62af533a (commit) via a3ab86d6b4b54f2c27e354131600f904767a325a (commit) from 742e9a0888b4a7f340e8d23635ee681582a2c9d1 (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 76e04eac072c41936ed4ce088a1903ff62af533a Merge: 742e9a0 a3ab86d Author: Lawrence Sebald <ljs...@us...> Date: Mon Aug 28 00:07:14 2023 -0400 Merge pull request #277 from KallistiOS/tiny-thread-cleanups Small cleanups to thread.h and thread.c commit a3ab86d6b4b54f2c27e354131600f904767a325a Author: Lawrence Sebald <ljs...@us...> Date: Fri Aug 25 19:46:19 2023 -0400 Small cleanups to thread.h and thread.c. - Normalized a bunch of formatting. - Added restrict to two pointers. ----------------------------------------------------------------------- Summary of changes: include/kos/thread.h | 38 +++++++++++++++++++------------------- kernel/thread/thread.c | 38 +++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/include/kos/thread.h b/include/kos/thread.h index 197c941..8464c7d 100644 --- a/include/kos/thread.h +++ b/include/kos/thread.h @@ -63,7 +63,7 @@ __BEGIN_DECLS thd_detach()). The old KOS threading system only had what would be considered detached threads. - \sa semaphore_t, mutex_t, kthread_once_t, kthread_key_t + \sa semaphore_t, mutex_t, kthread_once_t, kthread_key_t, rw_semaphore_t */ /** \brief Maximal thread priority. @@ -140,11 +140,11 @@ typedef struct kthread { /** \brief Generic wait target, if waiting. \see kos/genwait.h */ - void * wait_obj; + void *wait_obj; /** \brief Generic wait message, if waiting. \see kos/genwait.h */ - const char * wait_msg; + const char *wait_msg; /** \brief Wait timeout callback. @@ -153,7 +153,7 @@ typedef struct kthread { \param obj The object that we were waiting on. */ - void (*wait_callback)(void * obj); + void (*wait_callback)(void *obj); /** \brief Next scheduled time. This value is used for sleep and timed block operations. This value is @@ -255,7 +255,7 @@ typedef struct kthread_attr { /** \defgroup thd_modes Threading system modes \ingroup threads - The threading system will always be in one of the following modes. This + The threading system will always be in one of the following modes. This represents either pre-emptive scheduling or an un-initialized state. @{ @@ -290,7 +290,7 @@ extern kthread_t *thd_current; \return Whatever the unblocker deems necessary to return. */ -int thd_block_now(irq_context_t * mycxt); +int thd_block_now(irq_context_t *mycxt); /** \brief Find a new thread to swap in. \ingroup threads @@ -305,7 +305,7 @@ int thd_block_now(irq_context_t * mycxt); \return The IRQ context of the thread selected. */ -irq_context_t * thd_choose_new(void); +irq_context_t *thd_choose_new(void); /** \brief Given a thread ID, locates the thread structure. \ingroup threads @@ -368,7 +368,7 @@ int thd_remove_from_runnable(kthread_t *thd); \sa thd_create_ex, thd_destroy */ -kthread_t *thd_create(int detach, void * (*routine)(void *param), void *param); +kthread_t *thd_create(int detach, void *(*routine)(void *param), void *param); /** \brief Create a new thread with the specified set of attributes. \ingroup threads @@ -386,8 +386,8 @@ kthread_t *thd_create(int detach, void * (*routine)(void *param), void *param); \sa thd_create, thd_destroy */ -kthread_t *thd_create_ex(kthread_attr_t *attr, void *(*routine)(void *), - void *param); +kthread_t *thd_create_ex(const kthread_attr_t *restrict attr, + void *(*routine)(void *param), void *param); /** \brief Brutally kill the given thread. \ingroup threads @@ -422,7 +422,7 @@ void thd_exit(void *rv) __noreturn; \ingroup threads This function is the thread scheduler, and is generally called from a timer - interrupt. You will most likely never have a reason to call this function + interrupt. You will most likely never have a reason to call this function directly. For most cases, you'll want to set front_of_line to zero, but read the @@ -520,7 +520,7 @@ const char *thd_get_label(kthread_t *thd); \sa thd_get_label */ -void thd_set_label(kthread_t *thd, const char *label); +void thd_set_label(kthread_t *thd, const char *restrict label); /** \brief Retrieve the thread's current working directory. \ingroup threads @@ -553,7 +553,7 @@ const char *thd_get_pwd(kthread_t *thd); \sa thd_get_pwd */ -void thd_set_pwd(kthread_t *thd, const char *pwd); +void thd_set_pwd(kthread_t *thd, const char *restrict pwd); /** \brief Retrieve a pointer to the thread errno. \ingroup threads @@ -566,7 +566,7 @@ void thd_set_pwd(kthread_t *thd, const char *pwd); \return A pointer to the thread's errno. */ -int * thd_get_errno(kthread_t *thd); +int *thd_get_errno(kthread_t *thd); /** \brief Retrieve a pointer to the thread reent struct. \ingroup threads @@ -579,7 +579,7 @@ int * thd_get_errno(kthread_t *thd); \return The thread's reent struct. */ -struct _reent * thd_get_reent(kthread_t *thd); +struct _reent *thd_get_reent(kthread_t *thd); /** \brief Change threading modes. \ingroup threads @@ -595,7 +595,7 @@ struct _reent * thd_get_reent(kthread_t *thd); \sa thd_get_mode */ -int thd_set_mode(int mode) __attribute__((deprecated)); +int thd_set_mode(int mode) __deprecated; /** \brief Fetch the current threading mode. \ingroup threads @@ -609,7 +609,7 @@ int thd_set_mode(int mode) __attribute__((deprecated)); \sa thd_set_mode */ -int thd_get_mode(void) __attribute__((deprecated)); +int thd_get_mode(void) __deprecated; /** \brief Wait for a thread to exit. \ingroup threads @@ -628,7 +628,7 @@ int thd_get_mode(void) __attribute__((deprecated)); \sa thd_detach */ -int thd_join(kthread_t * thd, void **value_ptr); +int thd_join(kthread_t *thd, void **value_ptr); /** \brief Detach a joinable thread. \ingroup threads @@ -657,7 +657,7 @@ int thd_detach(kthread_t *thd); \sa thd_pslist */ -int thd_each(int (*cb)(kthread_t* thd, void* user_data), void* data); +int thd_each(int (*cb)(kthread_t *thd, void *user_data), void *data); /** \brief Print a list of all threads using the given print function. \ingroup threads diff --git a/kernel/thread/thread.c b/kernel/thread/thread.c index bec84ab..a0fa789 100644 --- a/kernel/thread/thread.c +++ b/kernel/thread/thread.c @@ -68,7 +68,7 @@ static kthread_t *thd_idle_thd = NULL; /*****************************************************************************/ /* Debug */ -static const char *thd_state_to_str(kthread_t * thd) { +static const char *thd_state_to_str(kthread_t *thd) { switch(thd->state) { case STATE_ZOMBIE: return "zombie"; @@ -90,7 +90,7 @@ static const char *thd_state_to_str(kthread_t * thd) { } } -int thd_each(int (*cb)(kthread_t* thd, void* user_data), void* data) { +int thd_each(int (*cb)(kthread_t *thd, void *user_data), void *data) { kthread_t *cur; LIST_FOREACH(cur, &thd_list, t_list) { @@ -226,7 +226,7 @@ static void *thd_reaper(void *param) { /* Thread execution wrapper; when the thd_create function below adds a new thread to the thread chain, this function is the one that gets called in the new context. */ -static void thd_birth(void * (*routine)(void *param), void *param) { +static void thd_birth(void *(*routine)(void *param), void *param) { /* Call the thread function */ void *rv = routine(param); @@ -328,8 +328,8 @@ int thd_remove_from_runnable(kthread_t *thd) { /* New thread function; given a routine address, it will create a new kernel thread with the given attributes. When the routine returns, the thread will exit. Returns the new thread struct. */ -kthread_t *thd_create_ex(kthread_attr_t *attr, void * (*routine)(void *param), - void *param) { +kthread_t *thd_create_ex(const kthread_attr_t *restrict attr, + void *(*routine)(void *param), void *param) { kthread_t *nt = NULL; tid_t tid; uint32_t params[4]; @@ -625,7 +625,7 @@ void thd_schedule_next(kthread_t *thd) { } /* See kos/thread.h for description */ -irq_context_t * thd_choose_new(void) { +irq_context_t *thd_choose_new(void) { uint64_t now = timer_ms_gettime64(); //printf("thd_choose_new() woken at %d\n", (uint32_t)now); @@ -663,7 +663,8 @@ static void thd_timer_hnd(irq_context_t *context) { void thd_sleep(int ms) { /* This should never happen. This should, perhaps, assert. */ if(thd_mode == THD_MODE_NONE) { - dbglog(DBG_WARNING, "thd_sleep called when threading not initialized.\n"); + dbglog(DBG_WARNING, "thd_sleep called when threading not " + "initialized.\n"); timer_spin_sleep(ms); return; } @@ -693,7 +694,7 @@ void thd_pass(void) { } /* Wait for a thread to exit */ -int thd_join(kthread_t * thd, void **value_ptr) { +int thd_join(kthread_t *thd, void **value_ptr) { int old, rv; kthread_t * t = NULL; @@ -702,9 +703,9 @@ int thd_join(kthread_t * thd, void **value_ptr) { return -1; if((rv = irq_inside_int())) { - dbglog(DBG_WARNING, "thd_join(%p) called inside an interrupt with code: %x evt: %.4x\n", - (void *)thd, - ((rv>>16) & 0xf), (rv & 0xffff)); + dbglog(DBG_WARNING, "thd_join(%p) called inside an interrupt with " + "code: %x evt: %.4x\n", (void *)thd, ((rv >> 16) & 0xf), + (rv & 0xffff)); return -1; } @@ -721,7 +722,7 @@ int thd_join(kthread_t * thd, void **value_ptr) { if(t != thd) { rv = -2; } - else if(thd->flags & THD_DETACHED) { + else if((thd->flags & THD_DETACHED)) { /* Can't join a detached thread */ rv = -3; } @@ -791,7 +792,7 @@ const char *thd_get_label(kthread_t *thd) { return thd->label; } -void thd_set_label(kthread_t *thd, const char *label) { +void thd_set_label(kthread_t *thd, const char *restrict label) { strncpy(thd->label, label, sizeof(thd->label) - 1); } @@ -805,15 +806,15 @@ const char *thd_get_pwd(kthread_t *thd) { return thd->pwd; } -void thd_set_pwd(kthread_t *thd, const char *pwd) { +void thd_set_pwd(kthread_t *thd, const char *restrict pwd) { strncpy(thd->pwd, pwd, sizeof(thd->pwd) - 1); } -int * thd_get_errno(kthread_t * thd) { +int *thd_get_errno(kthread_t *thd) { return &thd->thd_errno; } -struct _reent * thd_get_reent(kthread_t *thd) { +struct _reent *thd_get_reent(kthread_t *thd) { return &thd->thd_reent; } @@ -821,9 +822,8 @@ struct _reent * thd_get_reent(kthread_t *thd) { /* Change threading modes */ int thd_set_mode(int mode) { - - dbglog(DBG_WARNING, "thd_set_mode has no effect. Cooperative threading \ - mode is deprecated. KOS is always in pre-emptive threading mode. \n"); + dbglog(DBG_WARNING, "thd_set_mode() has no effect. Cooperative threading " + "mode is deprecated. Threading is always in preemptive mode.\n"); return mode; } hooks/post-receive -- A pseudo Operating System for the Dreamcast. |