jbuffer
|
Bounded-buffer implementation to manage integer values, supporting multiple readers but only a single writer. More...
#include <stdlib.h>
Go to the source code of this file.
Typedefs | |
typedef struct BNDBUF | BNDBUF |
Functions | |
BNDBUF * | bbCreate (size_t size) |
Creates a new bounded buffer. More... | |
void | bbDestroy (BNDBUF *bb) |
Destroys a bounded buffer. More... | |
void | bbPut (BNDBUF *bb, int value) |
Adds an element to a bounded buffer. More... | |
int | bbGet (BNDBUF *bb) |
Retrieves an element from a bounded buffer. More... | |
Bounded-buffer implementation to manage integer values, supporting multiple readers but only a single writer.
The bbuffer module uses the sem module API to synchronize concurrent access of readers and writers to the bounded buffer.
BNDBUF * bbCreate | ( | size_t | size | ) |
Creates a new bounded buffer.
This function creates a new bounded buffer and all the required helper data structures, including semaphores for synchronization. If an error occurs during the initialization, the implementation frees all resources already allocated by then.
size | The number of integers that can be stored in the bounded buffer. |
NULL
if an error occurred. void bbDestroy | ( | BNDBUF * | bb | ) |
Destroys a bounded buffer.
All resources associated with the bounded buffer are released.
bb | Handle of the bounded buffer that shall be freed. If a NULL pointer is passed, the implementation does nothing. |
int bbGet | ( | BNDBUF * | bb | ) |
Retrieves an element from a bounded buffer.
This function removes an element from a bounded buffer. If the buffer is empty, the function blocks until an element has been added.
bb | Handle of the bounded buffer. |
void bbPut | ( | BNDBUF * | bb, |
int | value | ||
) |
Adds an element to a bounded buffer.
This function adds an element to a bounded buffer. If the buffer is full, the function blocks until an element has been removed from it.
bb | Handle of the bounded buffer. |
value | Value that shall be added to the buffer. |