r3/include/r3_queue.h

49 lines
1,008 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>
2014-05-23 22:29:54 -04:00
struct _queue;
struct _queue_node;
typedef struct _queue_node queue_node;
typedef struct _queue queue;
2014-05-23 22:17:54 -04:00
struct _queue_node {
void *data;
2014-05-23 22:29:54 -04:00
queue * next;
2014-05-23 22:17:54 -04:00
};
2014-05-23 22:29:54 -04:00
// typedef struct _queue_node queue_node;
2014-05-23 22:17:54 -04:00
2014-05-23 22:29:54 -04:00
struct _queue {
2014-05-23 22:17:54 -04:00
queue_node * first;
queue_node * last;
2014-05-23 22:29:54 -04:00
};
2014-05-23 22:17:54 -04:00
// create and return the queue
2014-05-23 22:24:57 -04:00
queue * queue_new(void);
2014-05-23 22:17:54 -04:00
// destory the queue (free all the memory associate with the que even the data)
2014-05-23 22:24:57 -04:00
void queue_free(queue * que);
2014-05-23 22:17:54 -04:00
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 */