diff --git a/src/qxk/qxk_mutex.c b/src/qxk/qxk_mutex.c
index 5be26397..f6193989 100644
--- a/src/qxk/qxk_mutex.c
+++ b/src/qxk/qxk_mutex.c
@@ -5,8 +5,8 @@
* QXMutex_unlock() definitions.
* @cond
******************************************************************************
-* Last updated for version 6.0.3
-* Last updated on 2017-12-08
+* Last updated for version 6.1.1
+* Last updated on 2018-02-22
*
* Q u a n t u m L e a P s
* ---------------------------
@@ -33,7 +33,7 @@
* along with this program. If not, see .
*
* Contact information:
-* https://state-machine.com
+* https://www.state-machine.com
* mailto:info@state-machine.com
******************************************************************************
* @endcond
@@ -94,10 +94,11 @@ void QXMutex_init(QXMutex * const me, uint_fast8_t ceiling) {
Q_REQUIRE_ID(100,
(ceiling <= (uint_fast8_t)QF_MAX_ACTIVE)
&& ((ceiling == (uint_fast8_t)0)
- || (QF_active_[ceiling] == (QActive *)0)));
+ || (QF_active_[ceiling] == (QActive *)0)));
- me->ceiling = (uint8_t)ceiling;
- me->lockNest = (uint8_t)0;
+ me->ceiling = (uint8_t)ceiling;
+ me->lockNest = (uint8_t)0;
+ me->holderPrio = (uint8_t)0;
QF_bzero(&me->waitSet, (uint_fast16_t)sizeof(me->waitSet));
if (ceiling != (uint_fast8_t)0) {
@@ -166,7 +167,8 @@ bool QXMutex_lock(QXMutex * const me,
QPSet_remove(&QXK_attr_.readySet,
(uint_fast8_t)curr->super.startPrio);
- QPSet_insert(&QXK_attr_.readySet, (uint_fast8_t)curr->super.prio);
+ QPSet_insert(&QXK_attr_.readySet,
+ (uint_fast8_t)curr->super.prio);
}
me->holderPrio = (uint8_t)curr->super.startPrio;
@@ -208,9 +210,10 @@ bool QXMutex_lock(QXMutex * const me,
QF_CRIT_EXIT_NOP(); /* BLOCK here */
QF_CRIT_ENTRY_();
- /* the blocking object must be this mutex */
+ /* the blocking object of the current thread must be this mutex */
Q_ASSERT_ID(240, curr->super.super.temp.obj == (QMState *)me);
- curr->super.super.temp.obj = (QMState const *)0; /* clear */
+
+ curr->super.super.temp.obj = (QMState *)0; /* clear blocking obj. */
}
QF_CRIT_EXIT_();
@@ -299,8 +302,8 @@ bool QXMutex_tryLock(QXMutex * const me) {
else { /* the mutex is alredy locked by a different thread */
if (me->ceiling != (uint8_t)0) {
/* the prio slot must be claimed by the mutex holder */
- Q_ASSERT_ID(330,
- QF_active_[me->ceiling] == QF_active_[me->holderPrio]);
+ Q_ASSERT_ID(330, (me->holderPrio != (uint8_t)0)
+ && (QF_active_[me->ceiling] == QF_active_[me->holderPrio]));
}
curr = (QActive *)0; /* means that mutex is NOT available */
}
@@ -369,7 +372,7 @@ void QXMutex_unlock(QXMutex * const me) {
/* the mutex no longer held by a thread */
me->holderPrio = (uint8_t)0;
- QS_BEGIN_NOCRIT_(QS_MUTEX_UNLOCK, (void *)0, (void *)0)
+ QS_BEGIN_NOCRIT_(QS_MUTEX_UNLOCK, (void *)0, curr)
QS_TIME_(); /* timestamp */
QS_2U8_((uint8_t)curr->startPrio, /* the start priority */
me->ceiling); /* the mutex ceiling */
@@ -414,6 +417,7 @@ void QXMutex_unlock(QXMutex * const me) {
/* make thr the new mutex holder */
me->holderPrio = (uint8_t)thr->super.startPrio;
+
/* make the thread ready to run (at the ceiling prio) */
QPSet_insert(&QXK_attr_.readySet, (uint_fast8_t)thr->super.prio);
@@ -437,7 +441,7 @@ void QXMutex_unlock(QXMutex * const me) {
QXK_activate_(); /* activate a basic thread */
}
}
- else { /* releasing the */
+ else { /* releasing the mutex */
--me->lockNest; /* release one level */
}
QF_CRIT_EXIT_();
diff --git a/src/qxk/qxk_sema.c b/src/qxk/qxk_sema.c
index 0c599758..22ee957e 100644
--- a/src/qxk/qxk_sema.c
+++ b/src/qxk/qxk_sema.c
@@ -4,8 +4,8 @@
* @ingroup qxk
* @cond
******************************************************************************
-* Last updated for version 6.0.3
-* Last updated on 2017-12-08
+* Last updated for version 6.1.1
+* Last updated on 2018-02-22
*
* Q u a n t u m L e a P s
* ---------------------------
@@ -32,7 +32,7 @@
* along with this program. If not, see .
*
* Contact information:
-* https://state-machine.com
+* https://www.state-machine.com
* mailto:info@state-machine.com
******************************************************************************
* @endcond
@@ -98,7 +98,7 @@ void QXSemaphore_init(QXSemaphore * const me, uint_fast16_t count,
* resumes the highest-priority extended thread waiting for the semaphore.
*
* @param[in,out] me pointer (see @ref oop)
-* @param[in] nTicks number of clock ticks (at the associated rate)
+* @param[in] nTicks number of clock ticks (at the associated rate)
* to wait for the semaphore. The value of
* QXTHREAD_NO_TIMEOUT indicates that no timeout will
* occur and the semaphore will wait indefinitely.
@@ -147,7 +147,7 @@ bool QXSemaphore_wait(QXSemaphore * const me, uint_fast16_t const nTicks) {
QF_CRIT_ENTRY_();
/* the blocking object must be this semaphore */
Q_ASSERT_ID(210, curr->super.super.temp.obj == (QMState *)me);
- curr->super.super.temp.obj = (QMState const *)0; /* clear */
+ curr->super.super.temp.obj = (QMState *)0; /* clear */
}
QF_CRIT_EXIT_();
@@ -229,8 +229,14 @@ bool QXSemaphore_signal(QXSemaphore * const me) {
QPSet_remove(&me->waitSet, p);
thr = (QXThread *)QF_active_[p];
+ /* the thread must be registered in QF;
+ * the thread must be extended;
+ * must be blocked on this semaphore; and
+ * the semaphore count must be zero (semaphore not signaled)
+ */
Q_ASSERT_ID(410, (thr != (QXThread *)0) /* must be registered */
&& (thr->super.osObject != (struct QActive *)0) /* extended thr.*/
+ && (thr->super.super.temp.obj == (QMState const *)me)
&& (me->count == (uint16_t)0)); /* sema counter must be 0 */
/* disarm the internal time event */
diff --git a/src/qxk/qxk_xthr.c b/src/qxk/qxk_xthr.c
index e80df111..f4e3d719 100644
--- a/src/qxk/qxk_xthr.c
+++ b/src/qxk/qxk_xthr.c
@@ -316,7 +316,9 @@ static bool QXThread_post_(QActive * const me, QEvt const * const e,
else {
/* insert event into the ring buffer (FIFO) */
QF_PTR_AT_(me->eQueue.ring, me->eQueue.head) = e;
- if (me->eQueue.head == (QEQueueCtr)0) { /*need to wrap head?*/
+
+ /* need to wrap the head counter? */
+ if (me->eQueue.head == (QEQueueCtr)0) {
me->eQueue.head = me->eQueue.end; /* wrap around */
}
--me->eQueue.head; /* advance the head (counter clockwise) */
@@ -333,12 +335,12 @@ static bool QXThread_post_(QActive * const me, QEvt const * const e,
QS_BEGIN_NOCRIT_(QS_QF_ACTIVE_POST_ATTEMPT,
QS_priv_.locFilter[AO_OBJ], me)
- QS_TIME_(); /* timestamp */
- QS_OBJ_(sender); /* the sender object */
- QS_SIG_(e->sig); /* the signal of the event */
- QS_OBJ_(me); /* this active object (recipient) */
+ QS_TIME_(); /* timestamp */
+ QS_OBJ_(sender); /* the sender object */
+ QS_SIG_(e->sig); /* the signal of the event */
+ QS_OBJ_(me); /* this active object (recipient) */
QS_2U8_(e->poolId_, e->refCtr_); /* pool Id & ref Count */
- QS_EQC_(nFree); /* number of free entries */
+ QS_EQC_(nFree); /* number of free entries */
QS_EQC_((QEQueueCtr)margin); /* margin requested */
QS_END_NOCRIT_()
@@ -381,9 +383,10 @@ static void QXThread_postLIFO_(QActive * const me, QEvt const * const e) {
* receive QP events directly into its own built-in event queue from an ISR,
* basic thread (AO), or another extended thread.
*
-* If QXThread_queueGet() is called when no events are present in the thread's
-* event queue, the operation blocks the current extended thread until either
-* an event is received, or a user-specified timeout expires.
+* If QXThread_queueGet() is called when no events are present in the
+* thread's private event queue, the operation blocks the current extended
+* thread until either an event is received, or a user-specified timeout
+* expires.
*
* @param[in] nTicks number of clock ticks (at the associated rate)
* to wait for the event to arrive. The value of
@@ -451,11 +454,11 @@ QEvt const *QXThread_queueGet(uint_fast16_t const nTicks) {
QS_BEGIN_NOCRIT_(QS_QF_ACTIVE_GET,
QS_priv_.locFilter[AO_OBJ], thr)
- QS_TIME_(); /* timestamp */
- QS_SIG_(e->sig); /* the signal of this event */
+ QS_TIME_(); /* timestamp */
+ QS_SIG_(e->sig); /* the signal of this event */
QS_OBJ_(&thr->super); /* this active object */
QS_2U8_(e->poolId_, e->refCtr_); /* pool Id & ref Count */
- QS_EQC_(nFree); /* number of free entries */
+ QS_EQC_(nFree); /* number of free entries */
QS_END_NOCRIT_()
}
else {
@@ -466,8 +469,8 @@ QEvt const *QXThread_queueGet(uint_fast16_t const nTicks) {
QS_BEGIN_NOCRIT_(QS_QF_ACTIVE_GET_LAST,
QS_priv_.locFilter[AO_OBJ], thr)
- QS_TIME_(); /* timestamp */
- QS_SIG_(e->sig); /* the signal of this event */
+ QS_TIME_(); /* timestamp */
+ QS_SIG_(e->sig); /* the signal of this event */
QS_OBJ_(&thr->super); /* this active object */
QS_2U8_(e->poolId_, e->refCtr_); /* pool Id & ref Count */
QS_END_NOCRIT_()
@@ -580,7 +583,7 @@ bool QXThread_teDisarm_(QXThread * const me) {
}
/****************************************************************************/
-/*! delay (timed block) the current extended thread (static, no me-pointer) */
+/*! delay (timed blocking of) the current thread (static, no me-ptr) */
bool QXThread_delay(uint_fast16_t const nTicks) {
QXThread *thr;
QF_CRIT_STAT_