YaboWei / c-queue

A C based concurrent, FIFO queue.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

c-queue

@author: Matt Hartstonge (2015)

A C based concurrent, FIFO queue.

A concurrent FIFO Queue written in C. Takes in any type of data as underlying implementation is a linked list containing pointers to the actual data. Needs to be cast to (void *).

Uses POSIX semaphores and mutexes. Tested under linux, unsure of operation on Windows.

Usage

Queue *queue_alloc(int size);
void enqueue(Queue *queue, void *item);
void *dequeue(Queue *queue);

Code Examples

Below is a struct for the purposes of providing an example.

typedef struct {
    int value;
} Task;

Initalisation of a queue

Queue *queue = queue_alloc(QUEUE_SIZE);

Enqueuing (a Task) an item into a given Queue.

Task *task = (Task*)malloc(sizeof(Task));
task->value = i;
enqueue(queue, task);

Dequeuing (a Task) an item from a given Queue.

Task *task = (Task*)dequeue(queue);

About

A C based concurrent, FIFO queue.

License:GNU General Public License v3.0


Languages

Language:C 100.0%