From 477baaed5a9158b120ba9a485b285ba218d0d5cd Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 11 Apr 2017 11:08:36 +0000 Subject: Threads queues completed in NIL. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10155 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/osal/nil/osal.c | 64 -------------------------------------------------- os/hal/osal/nil/osal.h | 38 ++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 69 deletions(-) (limited to 'os/hal/osal') diff --git a/os/hal/osal/nil/osal.c b/os/hal/osal/nil/osal.c index e486641c5..863be6a75 100644 --- a/os/hal/osal/nil/osal.c +++ b/os/hal/osal/nil/osal.c @@ -48,68 +48,4 @@ /* Module exported functions. */ /*===========================================================================*/ -/** - * @brief Dequeues and wakes up one thread from the queue, if any. - * - * @param[in] tqp pointer to the threads queue object - * @param[in] msg the message code - * - * @iclass - */ -void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg) { - semaphore_t *sp = &tqp->sem; - - if (chSemGetCounterI(&tqp->sem) < (cnt_t)0) { - thread_t *tp = nil.threads; - while (true) { - /* Is this thread waiting on this semaphore?*/ - if (tp->u1.semp == sp) { - sp->cnt++; - - chDbgAssert(NIL_THD_IS_WTSEM(tp), "not waiting"); - - (void) chSchReadyI(tp, msg); - return; - } - tp++; - - chDbgAssert(tp < &nil.threads[CH_CFG_NUM_THREADS], - "pointer out of range"); - } - } -} - -/** - * @brief Dequeues and wakes up all threads from the queue. - * - * @param[in] tqp pointer to the threads queue object - * @param[in] msg the message code - * - * @iclass - */ -void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg) { - semaphore_t *sp = &tqp->sem; - thread_t *tp; - cnt_t cnt; - - cnt = sp->cnt; - sp->cnt = (cnt_t)0; - tp = nil.threads; - while (cnt < (cnt_t)0) { - - chDbgAssert(tp < &nil.threads[CH_CFG_NUM_THREADS], - "pointer out of range"); - - /* Is this thread waiting on this semaphore?*/ - if (tp->u1.semp == sp) { - - chDbgAssert(NIL_THD_IS_WTSEM(tp), "not waiting"); - - cnt++; - (void) chSchReadyI(tp, msg); - } - tp++; - } -} - /** @} */ diff --git a/os/hal/osal/nil/osal.h b/os/hal/osal/nil/osal.h index 4f81bd53a..807b660c2 100644 --- a/os/hal/osal/nil/osal.h +++ b/os/hal/osal/nil/osal.h @@ -219,6 +219,8 @@ struct event_source { */ typedef semaphore_t mutex_t; + +#if 0 /** * @brief Type of a thread queue. * @details A thread queue is a queue of sleeping threads, queued threads @@ -227,8 +229,9 @@ typedef semaphore_t mutex_t; * because there are no real threads. */ typedef struct { - semaphore_t sem; + thread_reference_t tr; } threads_queue_t; +#endif /*===========================================================================*/ /* Module macros. */ @@ -444,8 +447,7 @@ typedef struct { #ifdef __cplusplus extern "C" { #endif - void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg); - void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg); + #ifdef __cplusplus } #endif @@ -766,7 +768,7 @@ static inline void osalThreadResumeS(thread_reference_t *trp, msg_t msg) { */ static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) { - chSemObjectInit(&tqp->sem, (cnt_t)0); + chThdQueueObjectInit(tqp); } /** @@ -795,7 +797,33 @@ static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) { static inline msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, systime_t time) { - return chSemWaitTimeoutS(&tqp->sem, time); + return chThdEnqueueTimeoutS(tqp, time); +} + +/** + * @brief Dequeues and wakes up one thread from the queue, if any. + * + * @param[in] tqp pointer to the threads queue object + * @param[in] msg the message code + * + * @iclass + */ +static inline void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg) { + + chThdDequeueNextI(tqp, msg); +} + +/** + * @brief Dequeues and wakes up all threads from the queue. + * + * @param[in] tqp pointer to the threads queue object + * @param[in] msg the message code + * + * @iclass + */ +static inline void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg) { + + chThdDequeueAllI(tqp, msg); } /** -- cgit v1.2.3