|
ChibiOS/RT
2.5.1 |
|
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_USE_MESSAGES_PRIORITY option in chconf.h.
CH_USE_MESSAGES option must be enabled in chconf.h. Thread structure. Functions | |
| msg_t | chMsgSend (Thread *tp, msg_t msg) |
| Sends a message to the specified thread. | |
| Thread * | chMsgWait (void) |
| Suspends the thread and waits for an incoming message. | |
| void | chMsgRelease (Thread *tp, msg_t msg) |
| Releases a sender thread specifying a response message. | |
Macro Functions | |
| #define | chMsgIsPendingI(tp) ((tp)->p_msgqueue.p_next != (Thread *)&(tp)->p_msgqueue) |
| Evaluates to TRUE if the thread has pending messages. | |
| #define | chMsgGet(tp) ((tp)->p_msg) |
| Returns the message carried by the specified thread. | |
| #define | chMsgReleaseS(tp, msg) chSchWakeupS(tp, msg) |
| Releases the thread waiting on top of the messages queue. | |
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 68 of file chmsg.c.
References chDbgCheck, chSchGoSleepS(), chSchReadyI(), chSysLock, chSysUnlock, currp, Thread::p_msg, Thread::p_msgqueue, Thread::p_state, Thread::rdymsg, THD_STATE_SNDMSGQ, THD_STATE_WTMSG, and Thread::wtobjp.

| Thread * 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 99 of file chmsg.c.
References chMsgIsPendingI, chSchGoSleepS(), chSysLock, chSysUnlock, currp, fifo_remove(), Thread::p_state, THD_STATE_SNDMSG, and THD_STATE_WTMSG.

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 121 of file chmsg.c.
References chDbgAssert, chMsgReleaseS, chSysLock, chSysUnlock, Thread::p_state, and THD_STATE_SNDMSG.
| #define chMsgIsPendingI | ( | tp | ) | ((tp)->p_msgqueue.p_next != (Thread *)&(tp)->p_msgqueue) |
Evaluates to TRUE if the thread has pending messages.
Definition at line 43 of file chmsg.h.
Referenced by chMsgWait().
| #define chMsgGet | ( | tp | ) | ((tp)->p_msg) |
Returns the message carried by the specified thread.
chMsgWait().| [in] | tp | pointer to the thread |
| #define chMsgReleaseS | ( | tp, | |
| msg | |||
| ) | chSchWakeupS(tp, msg) |
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 68 of file chmsg.h.
Referenced by chMsgRelease().