ChibiOS 21.11.4
|
Synchronous inter-thread messages APIs and services.
Synchronous messages are an easy to use and fast IPC mechanism, threads can both act as message servers and/or message clients, the mechanism allows data to be carried in both directions. Note that messages are not copied between the client and server threads but just a pointer passed so the exchange is very time efficient.
Messages are scalar data types of type msg_t
that are guaranteed to be size compatible with data pointers. Note that on some architectures function pointers can be larger that msg_t
.
Messages are usually processed in FIFO order but it is possible to process them in priority order by enabling the CH_CFG_USE_MESSAGES_PRIORITY
option in chconf.h
.
CH_CFG_USE_MESSAGES
option must be enabled in chconf.h
. thread_t
structure.Macros | |
#define | __ch_msg_insert(qp, tp) |
Functions | |
msg_t | chMsgSend (thread_t *tp, msg_t msg) |
Sends a message to the specified thread. | |
thread_t * | chMsgWaitS (void) |
Suspends the thread and waits for an incoming message. | |
thread_t * | chMsgWaitTimeoutS (sysinterval_t timeout) |
Suspends the thread and waits for an incoming message or a timeout to occur. | |
thread_t * | chMsgPollS (void) |
Poll to check for an incoming message. | |
void | chMsgRelease (thread_t *tp, msg_t msg) |
Releases a sender thread specifying a response message. | |
static thread_t * | chMsgWait (void) |
Suspends the thread and waits for an incoming message. | |
static thread_t * | chMsgWaitTimeout (sysinterval_t timeout) |
Suspends the thread and waits for an incoming message or a timeout to occur. | |
static thread_t * | chMsgPoll (void) |
Poll to check for an incoming message. | |
static bool | chMsgIsPendingI (thread_t *tp) |
Evaluates to true if the thread has pending messages. | |
static msg_t | chMsgGet (thread_t *tp) |
Returns the message carried by the specified thread. | |
static void | chMsgReleaseS (thread_t *tp, msg_t msg) |
Releases the thread waiting on top of the messages queue. |
#define __ch_msg_insert | ( | qp, | |
tp ) |
Definition at line 54 of file rt/include/chmsg.h.
Referenced by chMsgSend().
Sends a message to the specified thread.
The sender is stopped until the receiver executes a chMsgRelease()after
receiving the message.
[in] | tp | the pointer to the thread |
[in] | msg | the message |
chMsgRelease()
.Definition at line 81 of file rt/src/chmsg.c.
References __ch_msg_insert, CH_STATE_SNDMSGQ, CH_STATE_WTMSG, chDbgCheck, chSchGoSleepS, chSchReadyI(), chSysLock, chSysUnlock, chThdGetSelfX, ch_thread::msgqueue, ch_thread::rdymsg, ch_thread::sentmsg, ch_thread::state, and ch_thread::u.
Referenced by chDelegateCallVeneer().
thread_t * chMsgWaitS | ( | void | ) |
Suspends the thread and waits for an incoming message.
chMsgGet()
must be called in order to retrieve the message and then chMsgRelease()
must be invoked in order to acknowledge the reception and send the answer. chMsgRelease()
because the sending thread is suspended until then. Definition at line 115 of file rt/src/chmsg.c.
References ch_queue_fifo_remove(), CH_STATE_SNDMSG, CH_STATE_WTMSG, chDbgCheckClassS, chMsgIsPendingI(), chSchGoSleepS, chThdGetSelfX, ch_thread::msgqueue, ch_thread::state, and threadref.
thread_t * chMsgWaitTimeoutS | ( | sysinterval_t | timeout | ) |
Suspends the thread and waits for an incoming message or a timeout to occur.
chMsgGet()
must be called in order to retrieve the message and then chMsgRelease()
must be invoked in order to acknowledge the reception and send the answer. chMsgRelease()
because the sending thread is suspended until then. [in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
NULL | if a timeout occurred. |
Definition at line 152 of file rt/src/chmsg.c.
References ch_queue_fifo_remove(), CH_STATE_SNDMSG, CH_STATE_WTMSG, chDbgCheckClassS, chMsgIsPendingI(), chSchGoSleepTimeoutS(), chThdGetSelfX, MSG_OK, ch_thread::msgqueue, ch_thread::state, and threadref.
Referenced by chMsgWaitTimeout().
thread_t * chMsgPollS | ( | void | ) |
Poll to check for an incoming message.
chMsgGet()
must be called in order to retrieve the message and then chMsgRelease()
must be invoked in order to acknowledge the reception and send the answer. chMsgRelease()
because the sending thread is suspended until then. NULL | if no incoming message waiting. |
Definition at line 186 of file rt/src/chmsg.c.
References ch_queue_fifo_remove(), CH_STATE_SNDMSG, chMsgIsPendingI(), chThdGetSelfX, ch_thread::msgqueue, ch_thread::state, and threadref.
Referenced by chMsgPoll().
Releases a sender thread specifying a response message.
chMsgWait()
.[in] | tp | pointer to the thread |
[in] | msg | message to be returned to the sender |
Definition at line 208 of file rt/src/chmsg.c.
References CH_STATE_SNDMSG, chDbgAssert, chMsgReleaseS, chSysLock, chSysUnlock, and ch_thread::state.
Referenced by chDelegateDispatch(), and chDelegateDispatchTimeout().
|
inlinestatic |
Suspends the thread and waits for an incoming message.
chMsgGet()
must be called in order to retrieve the message and then chMsgRelease()
must be invoked in order to acknowledge the reception and send the answer. chMsgRelease()
because the sending thread is suspended until then. Definition at line 95 of file rt/include/chmsg.h.
References chMsgWaitS, chSysLock, and chSysUnlock.
Referenced by chDelegateDispatch().
|
inlinestatic |
Suspends the thread and waits for an incoming message or a timeout to occur.
chMsgGet()
must be called in order to retrieve the message and then chMsgRelease()
must be invoked in order to acknowledge the reception and send the answer. chMsgRelease()
because the sending thread is suspended until then. [in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
NULL | if a timeout occurred. |
Definition at line 128 of file rt/include/chmsg.h.
References chMsgWaitTimeoutS(), chSysLock, and chSysUnlock.
Referenced by chDelegateDispatchTimeout().
|
inlinestatic |
Poll to check for an incoming message.
chMsgGet()
must be called in order to retrieve the message and then chMsgRelease()
must be invoked in order to acknowledge the reception and send the answer. chMsgRelease()
because the sending thread is suspended until then. NULL | if no incoming message waiting. |
Definition at line 155 of file rt/include/chmsg.h.
References chMsgPollS(), chSysLock, and chSysUnlock.
|
inlinestatic |
Evaluates to true
if the thread has pending messages.
[in] | tp | pointer to the thread |
Definition at line 173 of file rt/include/chmsg.h.
References chDbgCheckClassI, ch_thread::msgqueue, and ch_queue::next.
Referenced by chMsgPollS(), chMsgWaitS(), and chMsgWaitTimeoutS().
Returns the message carried by the specified thread.
chMsgWait()
.[in] | tp | pointer to the thread |
Definition at line 190 of file rt/include/chmsg.h.
References CH_STATE_SNDMSG, chDbgAssert, ch_thread::sentmsg, ch_thread::state, and ch_thread::u.
Releases the thread waiting on top of the messages queue.
chMsgWait()
.[in] | tp | pointer to the thread |
[in] | msg | message to be returned to the sender |
Definition at line 207 of file rt/include/chmsg.h.
References chDbgCheckClassS, and chSchWakeupS.