From c3b9392212cb43a5496c80f3d2ab61ce4caf1dab Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 19 Aug 2013 11:45:52 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6175 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chlists.h | 2 +- os/rt/include/chthreads.h | 1 + os/rt/src/chlists.c | 8 ++++---- os/rt/src/chschd.c | 3 +++ os/rt/src/chthreads.c | 36 +++++++++++++++++++++++++++++++++++- 5 files changed, 44 insertions(+), 6 deletions(-) (limited to 'os/rt') diff --git a/os/rt/include/chlists.h b/os/rt/include/chlists.h index 1384dc58f..f49ce679f 100644 --- a/os/rt/include/chlists.h +++ b/os/rt/include/chlists.h @@ -75,7 +75,7 @@ #ifdef __cplusplus extern "C" { #endif - msg_t chQueueGoSleepTimeoutS(threads_queue_t *tqp, systime_t time); + msg_t chQueueGoSleepTimeoutS(threads_queue_t *tqp, systime_t timeout); void chQueueWakeupOneI(threads_queue_t *tqp, msg_t msg); void chQueueWakeupAllI(threads_queue_t *tqp, msg_t msg); #ifdef __cplusplus diff --git a/os/rt/include/chthreads.h b/os/rt/include/chthreads.h index 18fb962d4..d53a0cb47 100644 --- a/os/rt/include/chthreads.h +++ b/os/rt/include/chthreads.h @@ -168,6 +168,7 @@ extern "C" { thread_t *chThdStart(thread_t *tp); tprio_t chThdSetPriority(tprio_t newprio); msg_t chThreadSuspendS(thread_reference_t *trp); + msg_t chThreadSuspendTimeoutS(thread_reference_t *trp, systime_t timeout); void chThreadResumeI(thread_reference_t *trp, msg_t msg); void chThreadResumeS(thread_reference_t *trp, msg_t msg); void chThreadResume(thread_reference_t *trp, msg_t msg); diff --git a/os/rt/src/chlists.c b/os/rt/src/chlists.c index a0b4df08b..4dd141b9c 100644 --- a/os/rt/src/chlists.c +++ b/os/rt/src/chlists.c @@ -57,7 +57,7 @@ * dequeued or the specified timeouts expires. * * @param[in] tqp pointer to the threads queue object - * @param[in] time the timeout in system ticks, the special values are + * @param[in] timeout the timeout in system ticks, the special values are * handled as follow: * - @a TIME_INFINITE the thread enters an infinite sleep * state. @@ -74,13 +74,13 @@ * * @sclass */ -msg_t chQueueGoSleepTimeoutS(threads_queue_t *tqp, systime_t time) { +msg_t chQueueGoSleepTimeoutS(threads_queue_t *tqp, systime_t timeout) { - if (TIME_IMMEDIATE == time) + if (TIME_IMMEDIATE == timeout) return MSG_TIMEOUT; queue_insert(currp, tqp); - return chSchGoSleepTimeoutS(CH_STATE_QUEUED, time); + return chSchGoSleepTimeoutS(CH_STATE_QUEUED, timeout); } /** diff --git a/os/rt/src/chschd.c b/os/rt/src/chschd.c index 572b2f822..1e844b7b0 100644 --- a/os/rt/src/chschd.c +++ b/os/rt/src/chschd.c @@ -147,6 +147,9 @@ static void wakeup(void *p) { another thread with higher priority.*/ chSysUnlockFromISR(); return; + case CH_STATE_SUSPENDED: + *(thread_reference_t *)tp->p_u.wtobjp = NULL; + break; #if CH_CFG_USE_SEMAPHORES case CH_STATE_WTSEM: chSemFastSignalI((semaphore_t *)tp->p_u.wtobjp); diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c index 5aaaeb5aa..13e4c0346 100644 --- a/os/rt/src/chthreads.c +++ b/os/rt/src/chthreads.c @@ -280,14 +280,48 @@ tprio_t chThdSetPriority(tprio_t newprio) { * @sclass */ msg_t chThreadSuspendS(thread_reference_t *trp) { + thread_t *tp = chThdGetSelfX(); chDbgAssert(*trp == NULL, "not NULL"); - *trp = (thread_reference_t)chThdGetSelfX(); + *trp = tp; + tp->p_u.wtobjp = &trp; chSchGoSleepS(CH_STATE_SUSPENDED); return chThdGetSelfX()->p_msg; } +/** + * @brief Sends the current thread sleeping and sets a reference variable. + * @note This function must reschedule, it can only be called from thread + * context. + * + * @param[in] trp a pointer to a thread reference object + * @param[in] timeout the timeout in system ticks, the special values are + * handled as follow: + * - @a TIME_INFINITE the thread enters an infinite sleep + * state. + * - @a TIME_IMMEDIATE the thread is not enqueued and + * the function returns @p MSG_TIMEOUT as if a timeout + * occurred. + * . + * @return The wake up message. + * @retval MSG_TIMEOUT if the operation timed out. + * + * @sclass + */ +msg_t chThreadSuspendTimeoutS(thread_reference_t *trp, systime_t timeout) { + thread_t *tp = chThdGetSelfX(); + + chDbgAssert(*trp == NULL, "not NULL"); + + if (TIME_IMMEDIATE == timeout) + return MSG_TIMEOUT; + + *trp = tp; + tp->p_u.wtobjp = &trp; + return chSchGoSleepTimeoutS(CH_STATE_SUSPENDED, timeout); +} + /** * @brief Wakes up a thread waiting on a thread reference object. * @note This function must not reschedule because it can be called from -- cgit v1.2.3