aboutsummaryrefslogtreecommitdiffstats
path: root/os/kernel/src
diff options
context:
space:
mode:
Diffstat (limited to 'os/kernel/src')
-rw-r--r--os/kernel/src/chqueues.c23
-rw-r--r--os/kernel/src/chsys.c5
-rw-r--r--os/kernel/src/chthreads.c26
3 files changed, 34 insertions, 20 deletions
diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c
index cf3d21732..b32ccf803 100644
--- a/os/kernel/src/chqueues.c
+++ b/os/kernel/src/chqueues.c
@@ -152,9 +152,8 @@ msg_t chIQPutI(InputQueue *iqp, uint8_t b) {
* @details This function reads a byte value from an input queue. If the queue
* is empty then the calling thread is suspended until a byte arrives
* in the queue or a timeout occurs.
- * @note The callback is invoked if the queue is empty before entering the
- * @p THD_STATE_WTQUEUE state in order to solicit the low level to
- * start queue filling.
+ * @note The callback is invoked before reading the character from the
+ * buffer or before entering the state @p THD_STATE_WTQUEUE.
*
* @param[in] iqp pointer to an @p InputQueue structure
* @param[in] time the number of ticks before the operation timeouts,
@@ -172,12 +171,11 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) {
uint8_t b;
chSysLock();
+ if (iqp->q_notify)
+ iqp->q_notify(iqp);
+
while (chIQIsEmptyI(iqp)) {
msg_t msg;
-
- if (iqp->q_notify)
- iqp->q_notify(iqp);
-
if ((msg = qwait((GenericQueue *)iqp, time)) < Q_OK) {
chSysUnlock();
return msg;
@@ -201,9 +199,8 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) {
* been reset.
* @note The function is not atomic, if you need atomicity it is suggested
* to use a semaphore or a mutex for mutual exclusion.
- * @note The callback is invoked if the queue is empty before entering the
- * @p THD_STATE_WTQUEUE state in order to solicit the low level to
- * start queue filling.
+ * @note The callback is invoked before reading each character from the
+ * buffer or before entering the state @p THD_STATE_WTQUEUE.
*
* @param[in] iqp pointer to an @p InputQueue structure
* @param[out] bp pointer to the data buffer
@@ -227,10 +224,10 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp,
chSysLock();
while (TRUE) {
- while (chIQIsEmptyI(iqp)) {
- if (nfy)
- nfy(iqp);
+ if (nfy)
+ nfy(iqp);
+ while (chIQIsEmptyI(iqp)) {
if (qwait((GenericQueue *)iqp, time) != Q_OK) {
chSysUnlock();
return r;
diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c
index 866ee81a8..78caa88f6 100644
--- a/os/kernel/src/chsys.c
+++ b/os/kernel/src/chsys.c
@@ -36,10 +36,7 @@
#include "ch.h"
#if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__)
-/**
- * @brief Idle thread working area.
- * @see PORT_IDLE_THREAD_STACK_SIZE
- */
+/* Idle thread working area.*/
WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE);
/**
diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c
index 46039561b..7b48f2b00 100644
--- a/os/kernel/src/chthreads.c
+++ b/os/kernel/src/chthreads.c
@@ -32,8 +32,6 @@
* area. In this scenario static variables are shared among all
* threads while automatic variables are local to the thread.<br>
* Operations defined for threads:
- * - <b>Init</b>, a thread is prepared and put in the suspended
- * state.
* - <b>Create</b>, a thread is started on the specified thread
* function. This operation is available in multiple variants,
* both static and dynamic.
@@ -335,9 +333,29 @@ void chThdYield(void) {
* @api
*/
void chThdExit(msg_t msg) {
- Thread *tp = currp;
chSysLock();
+ chThdExitS(msg);
+ /* The thread never returns here.*/
+}
+
+/**
+ * @brief Terminates the current thread.
+ * @details The thread goes in the @p THD_STATE_FINAL state holding the
+ * specified exit status code, other threads can retrieve the
+ * exit status code by invoking the function @p chThdWait().
+ * @post Eventual code after this function will never be executed,
+ * this function never returns. The compiler has no way to
+ * know this so do not assume that the compiler would remove
+ * the dead code.
+ *
+ * @param[in] msg thread exit code
+ *
+ * @sclass
+ */
+void chThdExitS(msg_t msg) {
+ Thread *tp = currp;
+
tp->p_u.exitcode = msg;
#if defined(THREAD_EXT_EXIT_HOOK)
THREAD_EXT_EXIT_HOOK(tp);
@@ -353,6 +371,8 @@ void chThdExit(msg_t msg) {
REG_REMOVE(tp);
#endif
chSchGoSleepS(THD_STATE_FINAL);
+ /* The thread never returns here.*/
+ chDbgAssert(FALSE, "chThdExitS(), #1", "zombies apocalypse");
}
#if CH_USE_WAITEXIT || defined(__DOXYGEN__)