Mailboxes

Mailbox implementation.

enum @1
NON_BLOCKING = 0
non-blocking mode
BLOCKING
blocking mode
void mbox_init(mbox_t * mbox, msg_t * queue, unsigned int queue_size)

Initialize mbox object.

Note

The message queue size must be a power of two!

Parameters

mbox:ptr to mailbox to initialize
queue:array of msg_t used as queue
queue_size:number of msg_t objects in queue

int _mbox_put(mbox_t * mbox, msg_t * msg, int blocking)

Add message to mailbox.

If the mailbox is full, this function will return right away.

int _mbox_get(mbox_t * mbox, msg_t * msg, int blocking)

Get message from mailbox.

If the mailbox is empty, this function will return right away.

void mbox_put(mbox_t * mbox, msg_t * msg)

Add message to mailbox.

If the mailbox is full, this function will block until space becomes available.

Parameters

mbox:ptr to mailbox to operate on
msg:ptr to message that will be copied into mailbox

int mbox_try_put(mbox_t * mbox, msg_t * msg)

Add message to mailbox.

If the mailbox is full, this function will return right away.

Parameters

mbox:ptr to mailbox to operate on
msg:ptr to message that will be copied into mailbox

Return values

  • 1 if msg could be delivered
  • 0 otherwise
void mbox_get(mbox_t * mbox, msg_t * msg)

Get message from mailbox.

If the mailbox is empty, this function will block until a message becomes available.

Parameters

mbox:ptr to mailbox to operate on
msg:ptr to storage for retrieved message

int mbox_try_get(mbox_t * mbox, msg_t * msg)

Get message from mailbox.

If the mailbox is empty, this function will return right away.

Parameters

mbox:ptr to mailbox to operate on
msg:ptr to storage for retrieved message

Return values

  • 1 if msg could be retrieved
  • 0 otherwise
MBOX_INIT( queue, queue_size)

Static initializer for mbox objects.

1
{{0}, {0}, CIB_INIT(queue_size), queue}
struct mbox_t

Mailbox struct definition.

list.h::list_node_t readers

list of threads waiting for message

list.h::list_node_t writers

list of threads waiting to send

cib_t cib

cib for msg array

msg_t * msg_array

ptr to array of msg queue