MSGQ Module
2-232
Messages are sent and received via a
message queue
. A reader is a
thread that gets (reads) messages from a message queue. A writer is a
thread that puts (writes) a message to a message queue. Each message
queue has one reader and can have many writers. A thread may read
from or write to multiple message queues.
Figure 2-4.
Writers and Reader of a Message Queue
Conceptually, the reader thread owns a message queue. The processor
where the reader resides opens a message queue. Writer threads locate
existing message queues to get access to them.
Messages must be allocated from the MSGQ module. Once a message
is allocated, it can be sent on any message queue. Once a message is
sent, the writer loses ownership of the message and should not attempt
to modify the message. Once the reader receives the message, it owns
the message. It may either free the message or re-use the message.
Messages in a message queue can be of variable length. The only
requirement is that the first field in the definition of a message must be a
MSGQ_MsgHeader element.
typedef struct MyMsg {
MSGQ_MsgHeader header;
...
} MyMsg;
The MSGQ API uses the MSGQ_MsgHeader internally. Your application
should not modify or directly access the fields in the MSGQ_MsgHeader.
The MSGQ module has the following components:
❏
MSGQ API.
Applications call the MSGQ functions to open and use a
message queue object to send and receive messages. For an
overview, see “MSGQ APIs” on page 2-233. For details, see the
sections on the individual APIs.
M SG Q
object
W riter 1
Reader
W riter 2