aboutsummaryrefslogtreecommitdiffstats
path: root/src/chschd.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-01-23 14:50:42 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-01-23 14:50:42 +0000
commit68003a03c299850f0b66adfa4df6c9d6b6ba6ab2 (patch)
tree719bb767775d1cddb05f070b32b67abfa51a37e9 /src/chschd.c
parent1aecb14913213565c804dda42322c6fb3136827d (diff)
downloadChibiOS-68003a03c299850f0b66adfa4df6c9d6b6ba6ab2.tar.gz
ChibiOS-68003a03c299850f0b66adfa4df6c9d6b6ba6ab2.tar.bz2
ChibiOS-68003a03c299850f0b66adfa4df6c9d6b6ba6ab2.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@182 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src/chschd.c')
-rw-r--r--src/chschd.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/chschd.c b/src/chschd.c
index cbd1cfdd3..92a0fbb0d 100644
--- a/src/chschd.c
+++ b/src/chschd.c
@@ -90,6 +90,33 @@ void chSchGoSleepS(t_tstate newstate) {
chSysSwitchI(otp, currp);
}
+static void wakeup(void *p) {
+
+ if (((Thread *)p)->p_state == PRWTSEM)
+ chSemFastSignalI(((Thread *)p)->p_wtsemp);
+ chSchReadyI(p, RDY_TIMEOUT);
+}
+
+/**
+ * Puts the current thread to sleep into the specified state, the next highest
+ * priority thread becomes running. The thread is automatically awakened after
+ * the specified time elapsed.
+ * @param newstate the new thread state
+ * @param time the number of ticks before the operation timouts
+ * @return the wakeup message, it is \p RDY_TIMEOUT if a timeout occurs
+ * @note The function must be called in the system mutex zone.
+ * @note The function is not meant to be used in the user code directly.
+ */
+t_msg chSchGoSleepTimeoutS(t_tstate newstate, t_time time) {
+ VirtualTimer vt;
+
+ chVTSetI(&vt, time, wakeup, currp);
+ chSchGoSleepS(newstate);
+ if (chVTIsArmedI(&vt))
+ chVTResetI(&vt);
+ return currp->p_rdymsg;
+}
+
/**
* Wakeups a thread, the thread is inserted into the ready list or made
* running directly depending on its relative priority compared to the current