#ifndef mbox_h #define mbox_h /* Cesar project {{{ * * Copyright (C) 2009 Spidcom * * <<>> * * }}} */ /** * \file mbox.c * \brief Mailbox. * \ingroup lib * * Mailbox implementation. */ #include "hal/arch/sem.h" struct mbox_node_t { struct mbox_node_t *next; }; typedef struct mbox_node_t mbox_node_t; struct mbox_t { /** Semaphore counting the numbers of messages pending. */ hal_arch_sem_t sem; /** The list head. */ mbox_node_t *head; /** The list tail. */ mbox_node_t *tail; }; typedef struct mbox_t mbox_t; /** * Initialise the mailbox. * \param ctx the mailbox context. */ void mbox_init (mbox_t *ctx); /** * Uninitialise the mailbox. * \param ctx the mailbox context. */ void mbox_uninit (mbox_t *ctx); /** * Get the first message of the mailbox. * \param ctx the mailbox context. * * Block if the mailbox is empty, do not use in DSR. */ mbox_node_t* mbox_get (mbox_t *ctx); /** * Try to get a message of the mailbox. * \param ctx the mailbox context. * \return NULL if no message present. */ mbox_node_t* mbox_try_get (mbox_t *ctx); /** * Try to get the first message of the mailbox. * \param ctx the mailbox context. * \return the first message on success. * * Wait until the delay expire for a message, if no message was inserted it * returns NULL. */ mbox_node_t* mbox_timed_get (mbox_t *ctx, uint delay); /** * Insert a message in the mailbox. * \param ctx the mailbox context. * \param msg the message to insert. * * Can be called in the DSR. */ void mbox_put (mbox_t *ctx, mbox_node_t *msg); /** * Get the number of messages in the mailbox. * \param ctx the mailbox context. * \return the number of pending messages, */ uint mbox_peek (mbox_t *ctx); #endif /* mbox_h */