MSGQ_open
Application Program Interface
2-255
The default attributes are:
MSGQ_Attrs MSGQ_ATTRS = {
NULL, /* notifyHandle */
(MSGQ_Pend)SYS_zero, /* NOP pend */
FXN_F_nop /* NOP post */
};
The following typedefs are provided by the MSGQ module to allow easier
casting of the pend and post functions:
typedef Bool (*MSGQ_Pend)(Ptr notifyHandle, Uns timeout);
typedef Void (*MSGQ_Post)(Ptr notifyHandle);
The post() function you specify is always called within MSGQ_put when
a writer sends a message.
A reader calls MSGQ_get to receive a message. If there is a message, it
returns that message, and the pend() function is not called. The pend()
function is only called if there are no messages to receive.
The pend() and post() functions must act in a binary manner. For
instance, SEM_pend and SEM_post treat the semaphore as a counting
semaphore instead of binary. So SEM_pend and SEM_post are an
invalid pend/post pair. The following example, in which the reader calls
MSGQ_get with a timeout of SYS_FOREVER, shows why:
1) A writer sends 10 messages, making the count 10 in the semaphore.
2) The reader then calls MSGQ_get 10 times. Each call returns a
message without calling the pend() function.
3) The reader then calls MSGQ_get again. Since there are no
messages, the pend() function is called. Since the semaphore count
was 10, SEM_pend returns TRUE immediately from the pend().
MSGQ would check for messages and there would still be none, so
pend() would be called again. This would repeat 9 more times until
the count was zero.
If the pend() function were binary (for example, a binary semaphore), the
pend() function would be called at most two times in step 3.
So instead of using SEM_pend and SEM_post for synchronous
(blocking) opens, you should use SEM_pendBinary and
SEM_postBinary.
Pend
MSGQ_Pend
Function pointer to a user-specified pend function.
Post
MSGQ_Post
Function pointer to a user-specified post function.