aboutsummaryrefslogtreecommitdiffstats
path: root/os/rt
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-08-19 11:45:52 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-08-19 11:45:52 +0000
commitc3b9392212cb43a5496c80f3d2ab61ce4caf1dab (patch)
treec80a98cde7cba0c4d4d97e527211701a3f5dcd83 /os/rt
parentb4e2fca4a0ff8ed15625cdbf57cb4e8fe90c7647 (diff)
downloadChibiOS-c3b9392212cb43a5496c80f3d2ab61ce4caf1dab.tar.gz
ChibiOS-c3b9392212cb43a5496c80f3d2ab61ce4caf1dab.tar.bz2
ChibiOS-c3b9392212cb43a5496c80f3d2ab61ce4caf1dab.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6175 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/rt')
-rw-r--r--os/rt/include/chlists.h2
-rw-r--r--os/rt/include/chthreads.h1
-rw-r--r--os/rt/src/chlists.c8
-rw-r--r--os/rt/src/chschd.c3
-rw-r--r--os/rt/src/chthreads.c36
5 files changed, 44 insertions, 6 deletions
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,15 +280,49 @@ 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
* ISR context.