aboutsummaryrefslogtreecommitdiffstats
path: root/os/kernel/src
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-08-28 14:32:56 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-08-28 14:32:56 +0000
commitece6ef6bf70d1b3033687dedd23a9ce4cfc4f59b (patch)
tree6c7da3b4994a38fa023e8c4d734c0f1edf362037 /os/kernel/src
parentf58963c966bfd71eb7cf55daecb691b39f6f91cd (diff)
downloadChibiOS-ece6ef6bf70d1b3033687dedd23a9ce4cfc4f59b.tar.gz
ChibiOS-ece6ef6bf70d1b3033687dedd23a9ce4cfc4f59b.tar.bz2
ChibiOS-ece6ef6bf70d1b3033687dedd23a9ce4cfc4f59b.zip
Added assertions to the semaphores subsystem.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2138 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/kernel/src')
-rw-r--r--os/kernel/src/chsem.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c
index 2959b4d63..e5ec9afde 100644
--- a/os/kernel/src/chsem.c
+++ b/os/kernel/src/chsem.c
@@ -115,6 +115,11 @@ void chSemResetI(Semaphore *sp, cnt_t n) {
chDbgCheck((sp != NULL) && (n >= 0), "chSemResetI");
+ chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
+ ((sp->s_cnt < 0) && notempty(&sp->s_queue)),
+ "chSemResetI(), #1",
+ "inconsistent semaphore");
+
cnt = sp->s_cnt;
sp->s_cnt = n;
while (++cnt <= 0)
@@ -148,6 +153,11 @@ msg_t chSemWaitS(Semaphore *sp) {
chDbgCheck(sp != NULL, "chSemWaitS");
+ chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
+ ((sp->s_cnt < 0) && notempty(&sp->s_queue)),
+ "chSemWaitS(), #1",
+ "inconsistent semaphore");
+
if (--sp->s_cnt < 0) {
currp->p_u.wtobjp = sp;
sem_insert(currp, &sp->s_queue);
@@ -198,6 +208,11 @@ msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) {
chDbgCheck(sp != NULL, "chSemWaitTimeoutS");
+ chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
+ ((sp->s_cnt < 0) && notempty(&sp->s_queue)),
+ "chSemWaitTimeoutS(), #1",
+ "inconsistent semaphore");
+
if (--sp->s_cnt < 0) {
if (TIME_IMMEDIATE == time) {
sp->s_cnt++;
@@ -219,6 +234,11 @@ void chSemSignal(Semaphore *sp) {
chDbgCheck(sp != NULL, "chSemSignal");
+ chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
+ ((sp->s_cnt < 0) && notempty(&sp->s_queue)),
+ "chSemSignal(), #1",
+ "inconsistent semaphore");
+
chSysLock();
if (++sp->s_cnt <= 0)
chSchWakeupS(fifo_remove(&sp->s_queue), RDY_OK);
@@ -235,6 +255,11 @@ void chSemSignalI(Semaphore *sp) {
chDbgCheck(sp != NULL, "chSemSignalI");
+ chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
+ ((sp->s_cnt < 0) && notempty(&sp->s_queue)),
+ "chSemSignalI(), #1",
+ "inconsistent semaphore");
+
if (++sp->s_cnt <= 0) {
/* note, it is done this way in order to allow a tail call on
chSchReadyI().*/
@@ -260,6 +285,16 @@ msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) {
chDbgCheck((sps != NULL) && (spw != NULL), "chSemSignalWait");
+ chDbgAssert(((sps->s_cnt >= 0) && isempty(&sps->s_queue)) ||
+ ((sps->s_cnt < 0) && notempty(&sps->s_queue)),
+ "chSemSignalWait(), #1",
+ "inconsistent semaphore");
+
+ chDbgAssert(((spw->s_cnt >= 0) && isempty(&spw->s_queue)) ||
+ ((spw->s_cnt < 0) && notempty(&spw->s_queue)),
+ "chSemSignalWait(), #2",
+ "inconsistent semaphore");
+
chSysLock();
if (++sps->s_cnt <= 0)
chSchReadyI(fifo_remove(&sps->s_queue))->p_u.rdymsg = RDY_OK;