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

BNDBUFbb_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.

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

typedef struct BNDBUF BNDBUF

Opaque type of a bounded buffer.


Function Documentation

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.

Parameters:
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.

Parameters:
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.

Parameters:
bb Handle of the bounded buffer.
Returns:
The integer element.
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.

Parameters:
size The number of integers that can be stored in the bounded buffer.
Returns:
Handle for the created bounded buffer, or NULL if an error occurred.
 All Files Functions Typedefs