aboutsummaryrefslogtreecommitdiffstats
path: root/os/nil/include
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2017-04-11 09:23:49 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2017-04-11 09:23:49 +0000
commitca129dc5b437343cb35b38206363a9b5940971af (patch)
treecd9791a0ff49651d6917dcffb6ac03019bc6ab5d /os/nil/include
parent7b2d689e16bc11ce37cb21308f8b80d3827d910c (diff)
downloadChibiOS-ca129dc5b437343cb35b38206363a9b5940971af.tar.gz
ChibiOS-ca129dc5b437343cb35b38206363a9b5940971af.tar.bz2
ChibiOS-ca129dc5b437343cb35b38206363a9b5940971af.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10154 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/nil/include')
-rw-r--r--os/nil/include/ch.h53
1 files changed, 41 insertions, 12 deletions
diff --git a/os/nil/include/ch.h b/os/nil/include/ch.h
index cb32383cb..f21527c2d 100644
--- a/os/nil/include/ch.h
+++ b/os/nil/include/ch.h
@@ -111,12 +111,12 @@
executing. */
#define NIL_STATE_SLEEPING (tstate_t)1 /**< @brief Thread sleeping. */
#define NIL_STATE_SUSP (tstate_t)2 /**< @brief Thread suspended. */
-#define NIL_STATE_WTSEM (tstate_t)3 /**< @brief On semaphore. */
+#define NIL_STATE_WTQUEUE (tstate_t)3 /**< @brief On queue or semaph. */
#define NIL_STATE_WTOREVT (tstate_t)4 /**< @brief Waiting for events. */
#define NIL_THD_IS_READY(tr) ((tr)->state == NIL_STATE_READY)
#define NIL_THD_IS_SLEEPING(tr) ((tr)->state == NIL_STATE_SLEEPING)
#define NIL_THD_IS_SUSP(tr) ((tr)->state == NIL_STATE_SUSP)
-#define NIL_THD_IS_WTSEM(tr) ((tr)->state == NIL_STATE_WTSEM)
+#define NIL_THD_IS_WTQUEUE(tr) ((tr)->state == NIL_STATE_WTQUEUE)
#define NIL_THD_IS_WTOREVT(tr) ((tr)->state == NIL_STATE_WTOREVT)
/** @} */
@@ -474,18 +474,25 @@ typedef struct nil_thread thread_t;
#include "chcore.h"
-#if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
/**
- * @brief Type of a structure representing a semaphore.
+ * @brief Structure representing a queue of threads.
*/
-typedef struct nil_semaphore semaphore_t;
+struct nil_threads_queue {
+ volatile cnt_t cnt; /**< @brief Threads Queue counter. */
+};
/**
- * @brief Structure representing a counting semaphore.
+ * @brief Type of a queue of threads.
*/
-struct nil_semaphore {
- volatile cnt_t cnt; /**< @brief Semaphore counter. */
-};
+typedef struct nil_threads_queue threads_queue_t;
+
+#if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Type of a structure representing a semaphore.
+ * @note Semaphores are implemented on thread queues, the object is the
+ * same, the behavior is slightly different.
+ */
+typedef threads_queue_t semaphore_t;
#endif /* CH_CFG_USE_SEMAPHORES == TRUE */
/**
@@ -526,9 +533,7 @@ struct nil_thread {
msg_t msg; /**< @brief Wake-up message. */
void *p; /**< @brief Generic pointer. */
thread_reference_t *trp; /**< @brief Pointer to thread reference.*/
-#if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
- semaphore_t *semp; /**< @brief Pointer to semaphore. */
-#endif
+ threads_queue_t *tqp; /**< @brief Pointer to thread queue. */
#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
eventmask_t ewmask; /**< @brief Enabled events mask. */
#endif
@@ -1126,6 +1131,27 @@ struct nil_system {
(void) chSchGoSleepTimeoutS(NIL_STATE_SLEEPING, (abstime) - \
chVTGetSystemTimeX())
+/**
+ * @brief Initializes a threads queue object.
+ *
+ * @param[out] tqp pointer to the threads queue object
+ *
+ * @init
+ */
+#define chThdQueueObjectInit(tqp) ((tqp)->cnt = (cnt_t)0)
+
+/**
+ * @brief Evaluates to @p true if the specified queue is empty.
+ *
+ * @param[out] tqp pointer to the threads queue object
+ * @return The queue status.
+ * @retval false if the queue is not empty.
+ * @retval true if the queue is empty.
+ *
+ * @iclass
+ */
+#define chThdQueueIsEmptyI(tqp) ((bool)(tqp->cnt >= (cnt_t)0))
+
#if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
/**
* @brief Initializes a semaphore with the specified counter value.
@@ -1341,6 +1367,9 @@ extern "C" {
void chThdResumeI(thread_reference_t *trp, msg_t msg);
void chThdSleep(systime_t timeout);
void chThdSleepUntil(systime_t abstime);
+ void chThdDoDequeueNextI(threads_queue_t *tqp, msg_t msg);
+ void chThdDequeueNextI(threads_queue_t *tqp, msg_t msg);
+ void chThdDequeueAllI(threads_queue_t *tqp, msg_t msg);
#if CH_CFG_USE_SEMAPHORES == TRUE
msg_t chSemWaitTimeout(semaphore_t *sp, systime_t timeout);
msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t timeout);