trafilo 0.1.0
Streaming event-handler framework in C
Loading...
Searching...
No Matches
bounded_queue.h
Go to the documentation of this file.
1#ifndef QUEUE_H
2#define QUEUE_H
3
4#include <stdlib.h>
5#include <stddef.h>
6#include <pthread.h>
7
12typedef struct {
13 void **buf; /* ring of capacity slots*/
14 size_t capacity;
15 size_t head; /* next slot to pop from*/
16 size_t tail; /* next slot to push into*/
17 size_t count; /* current occupancy */
18
19 pthread_mutex_t mu_lock;
20 pthread_cond_t not_empty; /*A conditional signal when queue is empty, blocks/frees consumers*/
21 pthread_cond_t not_full; /*A conditional signal when queue is full, blocks/frees producers*/
22
23 int done; /*Shutdown flag*/
25
31bounded_queue_t *bq_create(size_t capacity);
32
38
45int bq_push(bounded_queue_t *q, void *item);
46
52void *bq_pop(bounded_queue_t *q);
53
61#endif
int bq_push(bounded_queue_t *q, void *item)
Add an entry to the queue. Handles not_full, blocks while full.
Definition bounded_queue.c:42
void bq_destroy(bounded_queue_t *q)
Destroy the bounded queue and free resources.
Definition bounded_queue.c:32
void bq_shutdown(bounded_queue_t *q)
Handle clean shutdown when working queue is done. Responsible for handling all waiting workers on dea...
Definition bounded_queue.c:87
bounded_queue_t * bq_create(size_t capacity)
Create a bounded queue with a fixed capacity.
Definition bounded_queue.c:4
void * bq_pop(bounded_queue_t *q)
Pop an entry from the queue. Handles not_empty signal, blocks if empty.
Definition bounded_queue.c:66
A Circular ring queue, fixed size, to create a pool of events to be parsed.
Definition bounded_queue.h:12
pthread_mutex_t mu_lock
Definition bounded_queue.h:19
size_t count
Definition bounded_queue.h:17
pthread_cond_t not_full
Definition bounded_queue.h:21
pthread_cond_t not_empty
Definition bounded_queue.h:20
size_t capacity
Definition bounded_queue.h:14
void ** buf
Definition bounded_queue.h:13
size_t tail
Definition bounded_queue.h:16
size_t head
Definition bounded_queue.h:15
int done
Definition bounded_queue.h:23