libdatatypes 0.3.2
Abstract datatypes for C.
Loading...
Searching...
No Matches
asyncqueue.h File Reference

Asynchronous queue. More...

#include <pthread.h>
#include "datatypes.h"

Go to the source code of this file.

Data Structures

struct  AsyncQueue
 Asynchronous communication between threads. More...
 

Functions

AsyncQueueasync_queue_new (CompareFunc compare, FreeFunc free, Pool *pool)
 
void async_queue_init (AsyncQueue *queue, CompareFunc compare, FreeFunc free, Pool *pool)
 
void async_queue_destroy (AsyncQueue *queue)
 
void async_queue_free (AsyncQueue *queue)
 
void async_queue_push (AsyncQueue *queue, void *data)
 
bool async_queue_pop (AsyncQueue *queue, void *data)
 
bool async_queue_pop_timeout (AsyncQueue *queue, void *data, uint32_t ms)
 
void async_queue_clear (AsyncQueue *queue)
 
size_t async_queue_count (AsyncQueue *queue)
 

Detailed Description

Asynchronous queue.

Author
Sebastian Fedrau sebas.nosp@m.tian.nosp@m..fedr.nosp@m.au@g.nosp@m.mail..nosp@m.com

Definition in file asyncqueue.h.


Data Structure Documentation

◆ AsyncQueue

struct AsyncQueue

Asynchronous communication between threads.

Definition at line 35 of file asyncqueue.h.

Data Fields
pthread_cond_t cond

Condition to wakeup consumers.

pthread_mutex_t mutex

Mutex to protect the queue.

Queue queue

The underlying queue.

size_t waiting

Number of waiting consumers.

Function Documentation

◆ async_queue_clear()

void async_queue_clear ( AsyncQueue queue)
Parameters
queuean AsyncQueue

Clears a queue.

Definition at line 205 of file asyncqueue.c.

◆ async_queue_count()

size_t async_queue_count ( AsyncQueue queue)
Parameters
queuean AsyncQueue
Returns
number of items

Gets the number of stored items.

Definition at line 217 of file asyncqueue.c.

◆ async_queue_destroy()

void async_queue_destroy ( AsyncQueue queue)
Parameters
queuean AsyncQueue

Frees all items and the queue pointer.

Definition at line 74 of file asyncqueue.c.

◆ async_queue_free()

void async_queue_free ( AsyncQueue queue)
Parameters
queuean AsyncQueue

Frees all items without freeing the queue pointer.

Definition at line 92 of file asyncqueue.c.

◆ async_queue_init()

void async_queue_init ( AsyncQueue queue,
CompareFunc  compare,
FreeFunc  free,
Pool pool 
)
Parameters
queuean AsyncQueue
comparefunction to compare item data
freefunction to free item data or NULL
poola user-defined memory pool for creating/destroying QueueItems or NULL

Initializes an AsyncQueue.

Definition at line 61 of file asyncqueue.c.

◆ async_queue_new()

AsyncQueue * async_queue_new ( CompareFunc  compare,
FreeFunc  free,
Pool pool 
)
Parameters
comparefunction to compare item data
freefunction to free item data or NULL
poola user-defined memory pool for creating/destroying QueueItems or NULL
Returns
a new AsyncQueue

Creates a new AsyncQueue.

Definition at line 33 of file asyncqueue.c.

◆ async_queue_pop()

bool async_queue_pop ( AsyncQueue queue,
void *  data 
)
Parameters
queuean AsyncQueue
datalocation to store data of removed element
Returns
true on success

Pops data from the queue.

Definition at line 191 of file asyncqueue.c.

◆ async_queue_pop_timeout()

bool async_queue_pop_timeout ( AsyncQueue queue,
void *  data,
uint32_t  ms 
)
Parameters
queuean AsyncQueue
datalocation to store data of removed element
mstimeout in milliseconds
Returns
true on success

Pops data from the queue. Blocks for ms milliseconds.

Definition at line 199 of file asyncqueue.c.

◆ async_queue_push()

void async_queue_push ( AsyncQueue queue,
void *  data 
)
Parameters
queuean AsyncQueue
datadata to push

Pushs data onto the queue.

Definition at line 103 of file asyncqueue.c.