ChibiOS/RT
6.0.3
|
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. Functions | |
msg_t | chMsgSend (thread_t *tp, msg_t msg) |
Sends a message to the specified thread. More... | |
thread_t * | chMsgWait (void) |
Suspends the thread and waits for an incoming message. More... | |
void | chMsgRelease (thread_t *tp, msg_t msg) |
Releases a sender thread specifying a response message. More... | |
static bool | chMsgIsPendingI (thread_t *tp) |
Evaluates to true if the thread has pending messages. More... | |
static msg_t | chMsgGet (thread_t *tp) |
Returns the message carried by the specified thread. More... | |
static void | chMsgReleaseS (thread_t *tp, msg_t msg) |
Releases the thread waiting on top of the messages queue. More... | |
msg_t chMsgSend | ( | thread_t * | tp, |
msg_t | msg | ||
) |
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 87 of file chmsg.c.
References CH_STATE_SNDMSGQ, CH_STATE_WTMSG, chDbgCheck, chSchGoSleepS(), chSchReadyI(), chSysLock(), chSysUnlock(), currp, ch_thread::msgqueue, ch_thread::rdymsg, ch_thread::sentmsg, ch_thread::state, and ch_thread::u.
thread_t * chMsgWait | ( | 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 121 of file chmsg.c.
References CH_STATE_SNDMSG, CH_STATE_WTMSG, chMsgIsPendingI(), chSchGoSleepS(), chSysLock(), chSysUnlock(), currp, queue_fifo_remove(), and ch_thread::state.
void chMsgRelease | ( | thread_t * | tp, |
msg_t | msg | ||
) |
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 145 of file chmsg.c.
References CH_STATE_SNDMSG, chDbgAssert, chMsgReleaseS(), chSysLock(), chSysUnlock(), and ch_thread::state.
|
inlinestatic |
Evaluates to true
if the thread has pending messages.
[in] | tp | pointer to the thread |
Definition at line 79 of file chmsg.h.
References chDbgCheckClassI(), ch_thread::msgqueue, and ch_threads_queue::next.
Referenced by chMsgWait().
|
inlinestatic |
Returns the message carried by the specified thread.
chMsgWait()
.[in] | tp | pointer to the thread |
Definition at line 96 of file chmsg.h.
References CH_STATE_SNDMSG, chDbgAssert, ch_thread::sentmsg, ch_thread::state, and ch_thread::u.
|
inlinestatic |
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 113 of file chmsg.h.
References chDbgCheckClassS(), and chSchWakeupS().
Referenced by chMsgRelease().