trafilo 0.1.0
Streaming event-handler framework in C
Loading...
Searching...
No Matches
bounded_queue.h File Reference
#include <stdlib.h>
#include <stddef.h>
#include <pthread.h>

Go to the source code of this file.

Data Structures

struct  bounded_queue_t
 A Circular ring queue, fixed size, to create a pool of events to be parsed. More...

Functions

bounded_queue_tbq_create (size_t capacity)
 Create a bounded queue with a fixed capacity.
void bq_destroy (bounded_queue_t *q)
 Destroy the bounded queue and free resources.
int bq_push (bounded_queue_t *q, void *item)
 Add an entry to the queue. Handles not_full, blocks while full.
void * bq_pop (bounded_queue_t *q)
 Pop an entry from the queue. Handles not_empty signal, blocks if empty.
void bq_shutdown (bounded_queue_t *q)
 Handle clean shutdown when working queue is done. Responsible for handling all waiting workers on dead signals and setting the shutdown flag.

Function Documentation

◆ bq_create()

bounded_queue_t * bq_create ( size_t capacity)

Create a bounded queue with a fixed capacity.

Parameters
capacityThe maximum number of elements the queue can hold.
Returns
Pointer to a bounded_queue_t, NULL on bad-capacity or alloc failure.

◆ bq_destroy()

void bq_destroy ( bounded_queue_t * q)

Destroy the bounded queue and free resources.

Parameters
qThe bounded queue to destroy.

◆ bq_pop()

void * bq_pop ( bounded_queue_t * q)

Pop an entry from the queue. Handles not_empty signal, blocks if empty.

Parameters
qThe bounded queue.
Returns
Pointer to the popped item.

◆ bq_push()

int bq_push ( bounded_queue_t * q,
void * item )

Add an entry to the queue. Handles not_full, blocks while full.

Parameters
qThe bounded queue.
itemThe item to be added.
Returns
0 on success, -1 if shutdown is called while waiting on not_full.

◆ bq_shutdown()

void bq_shutdown ( bounded_queue_t * q)

Handle clean shutdown when working queue is done. Responsible for handling all waiting workers on dead signals and setting the shutdown flag.

Parameters
qThe bounded queue.