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 * | bb_init (size_t size) |
| Creates a new bounded buffer. | |
| void | bb_del (BNDBUF *bb) |
| Destroys a bounded buffer. | |
| void | bb_add (BNDBUF *bb, int value) |
| Adds an element to a bounded buffer. | |
| int | bb_get (BNDBUF *bb) |
| Retrieves an element from a bounded buffer. | |
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.
| void bb_add | ( | 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. |
| void bb_del | ( | 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. |
| int bb_get | ( | 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. |
| BNDBUF* bb_init | ( | 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.
1.7.1