A wait-free bounded FIFO of pointers for single producer/single consumer use.
More...
A wait-free bounded FIFO of pointers for single producer/single consumer use.
This FIFO is safe to use in single producer/single consumer patterns. In addition, the following restrictions apply for init/deinit:
a) nrf_fifo_enq() and nrf_fifo_deq() may only be called after nrf_fifo_init() is called.
b) All calls to nrf_fifo_enq() and nrf_fifo_deq() must be finished and no new calls must be made before nrf_fifo_deinit() is called.
These restrictions must be handled by the user of the module, for instance by using a mutex.
typedef void(* fifo_flush_fn)(void *p_data) |
Flush function called on deinit.
On deinit, this function will be called with each remaining element in the FIFO as argument. This can be used to ensure that memory is deallocated properly.
- Parameters
-
[in] | p_data | Pointer to data that is flushed from FIFO. |
typedef uint32_t(* fifo_wait_fn)(void) |
Wait function for blocking enqueue/dequeue.
Should return NRF_SUCCESS as long as there are no errors while waiting.
Function for deinitializing the FIFO.
Frees all memory allocated by this FIFO. All elements are removed. If a flush function was specified in nrf_fifo_init(), the function will be called for each remaining element in the FIFO.
- Parameters
-
[in,out] | p_fifo | The FIFO to deinitialize. |
uint32_t nrf_fifo_deq |
( |
nrf_fifo_t * |
p_fifo, |
|
|
void ** |
pp_ctx, |
|
|
bool |
wait |
|
) |
| |
Function for dequeuing an element from the FIFO.
- Parameters
-
[in,out] | p_fifo | The FIFO to dequeue elements from. |
[out] | pp_ctx | Pointer to where the dequeued element should be stored. |
[in] | wait | If true, this function will block until the FIFO has elements for dequeuing. Any errors returned by this function will be propagated to the caller. |
- Return values
-
NRF_SUCCESS | if the element was queued. |
NRF_ERROR_NO_MEM | if wait was set to false and no space was available. |
Function for checking if the FIFO is empty.
- Parameters
-
[in] | p_fifo | The FIFO to check. |
- Returns
- true if empty, false if not.
uint32_t nrf_fifo_enq |
( |
nrf_fifo_t * |
p_fifo, |
|
|
void * |
p_ctx, |
|
|
bool |
wait |
|
) |
| |
Function for enqueuing an element on the FIFO.
- Parameters
-
[in,out] | p_fifo | The FIFO to enqueue elements on. |
[in] | p_ctx | The pointer to enqueue. |
[in] | wait | If true, this function will block until the FIFO has available space. Any errors returned by this function will be propagated to the caller. |
- Return values
-
NRF_SUCCESS | if the element was queued. |
NRF_ERROR_NO_MEM | if wait was set to false and no space was available. |
Function for checking if the FIFO is full.
- Parameters
-
[in] | p_fifo | The FIFO to check. |
- Returns
- true if full, false if not.
Function for initializing the FIFO.
- Parameters
-
[out] | p_fifo | The FIFO to initialize. |
[in] | nmemb | The maximum number of elements in the FIFO. |
[in] | wait_fn | The wait function to use for blocking enqueue/dequeue. If NULL, the enq/deq functions will never block. |
[in] | flush_fn | The flush function to call on deinit. If NULL, the flush function will not be called. |
- Return values
-
NRF_SUCCESS | if fifo was initialized successfully. |