Mailboxes

Mailbox implementation. More...

Detailed Description

Mailbox implementation.

Files

file  mbox.h
 Mailbox API.
 

Data Structures

struct  mbox_t
 Mailbox struct definition. More...
 

Macros

#define MBOX_INIT(queue, queue_size)
 Static initializer for mbox objects. More...
 

Enumerations

enum  { NON_BLOCKING = 0, BLOCKING }
 

Functions

static void mbox_init (mbox_t *mbox, msg_t *queue, unsigned int queue_size)
 Initialize mbox object. More...
 
int _mbox_put (mbox_t *mbox, msg_t *msg, int blocking)
 Add message to mailbox. More...
 
int _mbox_get (mbox_t *mbox, msg_t *msg, int blocking)
 Get message from mailbox. More...
 
static void mbox_put (mbox_t *mbox, msg_t *msg)
 Add message to mailbox. More...
 
static int mbox_try_put (mbox_t *mbox, msg_t *msg)
 Add message to mailbox. More...
 
static void mbox_get (mbox_t *mbox, msg_t *msg)
 Get message from mailbox. More...
 
static int mbox_try_get (mbox_t *mbox, msg_t *msg)
 Get message from mailbox. More...
 
static size_t mbox_size (mbox_t *mbox)
 Get mbox queue size (capacity) More...
 
static size_t mbox_avail (mbox_t *mbox)
 Get messages available in mbox. More...
 

Macro Definition Documentation

◆ MBOX_INIT

#define MBOX_INIT (   queue,
  queue_size 
)
Value:
{ \
{ 0 }, { 0 }, CIB_INIT(queue_size), queue \
}

Static initializer for mbox objects.

Definition at line 34 of file mbox.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NON_BLOCKING 

non-blocking mode

BLOCKING 

blocking mode

Definition at line 48 of file mbox.h.

Function Documentation

◆ _mbox_get()

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.

◆ _mbox_put()

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.

◆ mbox_avail()

static size_t mbox_avail ( mbox_t mbox)
inlinestatic

Get messages available in mbox.

Returns the number of messages that can be retrieved without blocking.

Parameters
[in]mboxptr to mailbox to operate on
Returns
number of available messages

Definition at line 183 of file mbox.h.

◆ mbox_get()

static void mbox_get ( mbox_t mbox,
msg_t msg 
)
inlinestatic

Get message from mailbox.

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

Parameters
[in]mboxptr to mailbox to operate on
[in]msgptr to storage for retrieved message

Definition at line 141 of file mbox.h.

◆ mbox_init()

static void mbox_init ( mbox_t mbox,
msg_t queue,
unsigned int  queue_size 
)
inlinestatic

Initialize mbox object.

Note
The message queue size must be a power of two!
Parameters
[in]mboxptr to mailbox to initialize
[in]queuearray of msg_t used as queue
[in]queue_sizenumber of msg_t objects in queue

Definition at line 62 of file mbox.h.

◆ mbox_put()

static void mbox_put ( mbox_t mbox,
msg_t msg 
)
inlinestatic

Add message to mailbox.

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

Parameters
[in]mboxptr to mailbox to operate on
[in]msgptr to message that will be copied into mailbox

Definition at line 111 of file mbox.h.

◆ mbox_size()

static size_t mbox_size ( mbox_t mbox)
inlinestatic

Get mbox queue size (capacity)

Parameters
[in]mboxptr to mailbox to operate on
Returns
size of mbox queue (or 0 if there's no queue)

Definition at line 169 of file mbox.h.

◆ mbox_try_get()

static int mbox_try_get ( mbox_t mbox,
msg_t msg 
)
inlinestatic

Get message from mailbox.

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

Parameters
[in]mboxptr to mailbox to operate on
[in]msgptr to storage for retrieved message
Returns
1 if msg could be retrieved
0 otherwise

Definition at line 157 of file mbox.h.

◆ mbox_try_put()

static int mbox_try_put ( mbox_t mbox,
msg_t msg 
)
inlinestatic

Add message to mailbox.

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

Parameters
[in]mboxptr to mailbox to operate on
[in]msgptr to message that will be copied into mailbox
Returns
1 if msg could be delivered
0 otherwise

Definition at line 127 of file mbox.h.

CIB_INIT
#define CIB_INIT(SIZE)
Initialize cib_t to a given size.
Definition: cib.h:47