From de877486efb49378065f769ff423eef19ceb12e6 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 9 Apr 2011 15:10:15 +0000 Subject: Fixed bug 3276379. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2872 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/chsem.h | 2 +- os/kernel/src/chsem.c | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'os/kernel') diff --git a/os/kernel/include/chsem.h b/os/kernel/include/chsem.h index f33b294fa..04e079466 100644 --- a/os/kernel/include/chsem.h +++ b/os/kernel/include/chsem.h @@ -52,7 +52,7 @@ extern "C" { msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time); void chSemSignal(Semaphore *sp); void chSemSignalI(Semaphore *sp); - void chSemSetCounterI(Semaphore *sp, cnt_t n); + void chSemAddCounterI(Semaphore *sp, cnt_t n); #if CH_USE_SEMSW msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw); #endif diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index 3e0fcd0e8..c22a568ea 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -313,35 +313,32 @@ void chSemSignalI(Semaphore *sp) { } /** - * @brief Sets the semaphore counter to the specified value. - * @post After invoking this function all the threads waiting on the - * semaphore, if any, are released and the semaphore counter is set - * to the specified, non negative, value. + * @brief Adds the specified value to the semaphore counter. * @post This function does not reschedule so a call to a rescheduling * function must be performed before unlocking the kernel. Note that * interrupt handlers always reschedule on exit so an explicit * reschedule must not be performed in ISRs. * * @param[in] sp pointer to a @p Semaphore structure - * @param[in] n the new value of the semaphore counter. The value must - * be non-negative. + * @param[in] n value to be added to the semaphore counter. The value + * must be positive. * * @iclass */ -void chSemSetCounterI(Semaphore *sp, cnt_t n) { - cnt_t cnt; +void chSemAddCounterI(Semaphore *sp, cnt_t n) { - chDbgCheck((sp != NULL) && (n >= 0), "chSemSetCounterI"); + chDbgCheck((sp != NULL) && (n > 0), "chSemAddCounterI"); chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) || ((sp->s_cnt < 0) && notempty(&sp->s_queue)), - "chSemSetCounterI(), #1", + "chSemAddCounterI(), #1", "inconsistent semaphore"); - cnt = sp->s_cnt; - sp->s_cnt = n; - while (++cnt <= 0) - chSchReadyI(lifo_remove(&sp->s_queue))->p_u.rdymsg = RDY_OK; + while (n > 0) { + if (++sp->s_cnt <= 0) + chSchReadyI(fifo_remove(&sp->s_queue))->p_u.rdymsg = RDY_OK; + n--; + } } #if CH_USE_SEMSW -- cgit v1.2.3