From c303a8a06e68fb30c082a4f1a4fcc675ff0bd39e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 30 Nov 2007 09:00:50 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@121 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chqueues.c | 12 +++++------- src/chsem.c | 20 +++++++++++--------- src/include/semaphores.h | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/chqueues.c b/src/chqueues.c index 88eac2184..d0412598b 100644 --- a/src/chqueues.c +++ b/src/chqueues.c @@ -91,11 +91,10 @@ t_msg chIQGet(Queue *qp) { chSysLock(); - chSemWaitS(&qp->q_sem); - if (currp->p_rdymsg < RDY_OK) { + if (chSemWaitS(&qp->q_sem) < RDY_OK) { chSysUnlock(); - return currp->p_rdymsg; + return Q_RESET; } b = *qp->q_rdptr++; if (qp->q_rdptr >= qp->q_top) @@ -324,18 +323,17 @@ void chHDQInit(HalfDuplexQueue *qp, BYTE8 *buffer, t_size size, * Reads a byte from the receive queue, if the queue is empty or is in * transmission mode then the invoking thread is suspended. * @param qp pointer to a \p HalfDuplexQueue structure - * @return the byte value + * @return the byte value or \p Q_RESET if the queue was reset */ t_msg chHDQGetReceive(HalfDuplexQueue *qp) { BYTE8 b; chSysLock(); - chSemWaitS(&qp->hdq_isem); - if (currp->p_rdymsg < RDY_OK) { + if (chSemWaitS(&qp->hdq_isem) < RDY_OK) { chSysUnlock(); - return currp->p_rdymsg; + return Q_RESET; } /* * NOTE: The semaphore can be signaled only if the queue is in diff --git a/src/chsem.c b/src/chsem.c index 61fff37a1..01ec80649 100644 --- a/src/chsem.c +++ b/src/chsem.c @@ -82,33 +82,35 @@ void chSemResetI(Semaphore *sp, t_cnt n) { /** * Performs a wait operation on a semaphore. * @param sp pointer to a \p Semaphore structure + * @return the function can return \p RDY_OK or \p RDY_RESET. */ -void chSemWait(Semaphore *sp) { +t_msg chSemWait(Semaphore *sp) { + t_msg msg; chSysLock(); - if (--sp->s_cnt < 0) { - fifo_insert(currp, &sp->s_queue); - currp->p_semp = sp; - chSchGoSleepS(PRWTSEM); - } + msg = chSemWaitS(sp); chSysUnlock(); + return msg; } /** * Performs a wait operation on a semaphore. * @param sp pointer to a \p Semaphore structure + * @return the function can return \p RDY_OK or \p RDY_RESET. * @note This function must be called with interrupts disabled. * @note This function cannot be called by an interrupt handler. */ -void chSemWaitS(Semaphore *sp) { +t_msg chSemWaitS(Semaphore *sp) { if (--sp->s_cnt < 0) { fifo_insert(currp, &sp->s_queue); currp->p_semp = sp; chSchGoSleepS(PRWTSEM); + return currp->p_rdymsg; } + return RDY_OK; } #ifdef CH_USE_SEMAPHORES_TIMEOUT @@ -126,7 +128,7 @@ static void wakeup(void *p) { * Performs a wait operation on a semaphore with timeout specification. * @param sp pointer to a \p Semaphore structure * @param time the number of ticks before the operation fails - * @return the function can return \p RDY_OK. \p RDY_TIMEOUT or \p RDY_RESET. + * @return the function can return \p RDY_OK, \p RDY_TIMEOUT or \p RDY_RESET. */ t_msg chSemWaitTimeout(Semaphore *sp, t_time time) { t_msg msg; @@ -143,7 +145,7 @@ t_msg chSemWaitTimeout(Semaphore *sp, t_time time) { * Performs a wait operation on a semaphore with timeout specification. * @param sp pointer to a \p Semaphore structure * @param time the number of ticks before the operation fails - * @return the function can return \p RDY_OK. \p RDY_TIMEOUT or \p RDY_RESET. + * @return the function can return \p RDY_OK, \p RDY_TIMEOUT or \p RDY_RESET. * @note This function must be called with interrupts disabled. * @note This function cannot be called by an interrupt handler. * @note The function is available only if the \p CH_USE_SEMAPHORES_TIMEOUT diff --git a/src/include/semaphores.h b/src/include/semaphores.h index 4ffb3dc0d..e17d03a6a 100644 --- a/src/include/semaphores.h +++ b/src/include/semaphores.h @@ -43,8 +43,8 @@ extern "C" { void chSemInit(Semaphore *sp, t_cnt n); void chSemReset(Semaphore *sp, t_cnt n); void chSemResetI(Semaphore *sp, t_cnt n); - void chSemWait(Semaphore *sp); - void chSemWaitS(Semaphore *sp); + t_msg chSemWait(Semaphore *sp); + t_msg chSemWaitS(Semaphore *sp); #ifdef CH_USE_SEMAPHORES_TIMEOUT t_msg chSemWaitTimeout(Semaphore *sp, t_time time); t_msg chSemWaitTimeoutS(Semaphore *sp, t_time time); -- cgit v1.2.3