r3/include/r3_queue.h

44 lines
927 B
C
Raw Normal View History

2014-05-23 22:17:54 -04:00
/*
* r3_queue.h
* Copyright (C) 2014 c9s <c9s@c9smba.local>
*
* Distributed under terms of the MIT license.
*/
#ifndef R3_QUEUE_H
#define R3_QUEUE_H
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
struct _queue_node {
void *data;
struct _queue_node * next;
};
typedef struct _queue_node queue_node;
typedef struct {
queue_node * first;
queue_node * last;
} queue;
// create and return the queue
2014-05-23 22:20:37 -04:00
queue * queue_create(void);
2014-05-23 22:17:54 -04:00
// destory the queue (free all the memory associate with the que even the data)
void queue_destroy(queue * que);
2014-05-23 22:20:37 -04:00
// queue_push the data into queue
2014-05-23 22:17:54 -04:00
// data is expected to a pointer to a heap allocated memory
2014-05-23 22:20:37 -04:00
int queue_push(queue * que, void * data);
2014-05-23 22:17:54 -04:00
// return the data from the que (FIFO)
// and free up all the internally allocated memory
// but the user have to free the returning data pointer
2014-05-23 22:20:37 -04:00
void * queue_pop(queue * que);
2014-05-23 22:17:54 -04:00
#endif /* !R3_QUEUE_H */