diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/chmsg.c | 21 | ||||
-rw-r--r-- | src/include/threads.h | 2 | ||||
-rw-r--r-- | src/templates/chconf.h | 5 |
3 files changed, 28 insertions, 0 deletions
diff --git a/src/chmsg.c b/src/chmsg.c index 61546d7c1..20a59904e 100644 --- a/src/chmsg.c +++ b/src/chmsg.c @@ -36,7 +36,14 @@ t_msg chMsgSend(Thread *tp, t_msg msg) { chSysLock();
+#ifdef CH_USE_MESSAGES_PRIORITY
+ if (tp->p_flags & P_MSGBYPRIO)
+ prio_insert(currp, &tp->p_msgqueue);
+ else
+ fifo_insert(currp, &tp->p_msgqueue);
+#else
fifo_insert(currp, &tp->p_msgqueue);
+#endif
currp->p_msg = msg;
if (tp->p_state == PRWTMSG)
chSchReadyI(tp, RDY_OK);
@@ -67,7 +74,14 @@ t_msg chMsgSendWithEvent(Thread *tp, t_msg msg, EventSource *esp) { chSysLock();
chDbgAssert(tp->p_state != PRWTMSG, "chmsg.c, chMsgSendWithEvent()");
+#ifdef CH_USE_MESSAGES_PRIORITY
+ if (tp->p_flags & P_MSGBYPRIO)
+ prio_insert(currp, &tp->p_msgqueue);
+ else
+ fifo_insert(currp, &tp->p_msgqueue);
+#else
fifo_insert(currp, &tp->p_msgqueue);
+#endif
chEvtSendI(esp);
currp->p_msg = msg;
chSchGoSleepS(PRSNDMSG);
@@ -107,7 +121,14 @@ t_msg chMsgSendTimeout(Thread *tp, t_msg msg, t_time time) { chSysLock();
chVTSetI(&vt, time, wakeup, currp);
+#ifdef CH_USE_MESSAGES_PRIORITY
+ if (tp->p_flags & P_MSGBYPRIO)
+ prio_insert(currp, &tp->p_msgqueue);
+ else
+ fifo_insert(currp, &tp->p_msgqueue);
+#else
fifo_insert(currp, &tp->p_msgqueue);
+#endif
if (tp->p_state == PRWTMSG)
chSchReadyI(tp, RDY_OK);
currp->p_msg = msg;
diff --git a/src/include/threads.h b/src/include/threads.h index 50468e063..f451278cf 100644 --- a/src/include/threads.h +++ b/src/include/threads.h @@ -135,6 +135,8 @@ struct Thread { #define P_TERMINATE 1
/** Thread option: Create suspended thread.*/
#define P_SUSPENDED 2
+/** Thread option: Serve messages by priority instead of FIFO order.*/
+#define P_MSGBYPRIO 4
/** Pseudo priority used by the ready list header, do not use.*/
#define NOPRIO 0
diff --git a/src/templates/chconf.h b/src/templates/chconf.h index fb8ae6a69..d8e5f88da 100644 --- a/src/templates/chconf.h +++ b/src/templates/chconf.h @@ -108,6 +108,11 @@ * @note requires \p CH_USE_VIRTUAL_TIMERS.*/
#define CH_USE_MESSAGES_EVENT
+/** Configuration option: If enabled then the threads have an option to serve
+ * messages by priority instead of FIFO order.
+ * @note requires \p CH_USE_MESSAGES.*/
+#define CH_USE_MESSAGES_PRIORITY
+
/** Configuration option: if specified then the
* \p chThdGetExitEventSource() function is included in the kernel.
* @note requires \p CH_USE_MESSAGES.
|