jbuffer
Typedefs | Functions
jbuffer.h File Reference

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

BNDBUFbbCreate (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...
 

Detailed Description

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.

Typedef Documentation

◆ BNDBUF

typedef struct BNDBUF BNDBUF

Opaque type of a bounded buffer.

Function Documentation

◆ bbCreate()

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.

Parameters
sizeThe number of integers that can be stored in the bounded buffer.
Returns
Handle for the created bounded buffer, or NULL if an error occurred.

◆ bbDestroy()

void bbDestroy ( BNDBUF bb)

Destroys a bounded buffer.

All resources associated with the bounded buffer are released.

Parameters
bbHandle of the bounded buffer that shall be freed. If a NULL pointer is passed, the implementation does nothing.

◆ bbGet()

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.

Parameters
bbHandle of the bounded buffer.
Returns
The integer element.

◆ bbPut()

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.

Parameters
bbHandle of the bounded buffer.
valueValue that shall be added to the buffer.