From 68003a03c299850f0b66adfa4df6c9d6b6ba6ab2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 23 Jan 2008 14:50:42 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@182 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chschd.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/chschd.c') 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 -- cgit v1.2.3