iiotfeeder/queue.h
Wolfgang Hottgenroth a99c3b7121
queue and so on
2021-10-17 14:41:21 +02:00

33 lines
649 B
C

#include <stdint.h>
#include <pthread.h>
typedef struct s_queueBlock {
void *payload;
struct s_queueBlock *next;
} t_queueBlock;
typedef struct {
t_queueBlock *root;
t_queueBlock *head;
pthread_mutex_t head_lock;
t_queueBlock *tail;
pthread_mutex_t tail_lock;
pthread_mutex_t notEmptyLock;
pthread_cond_t notEmpty;
} t_queue;
t_queue *initQueue();
// allocate memory for the queueBlock on your own and fill in the payloadc
void putQueue(t_queue *queue, t_queueBlock *queueBlock);
// will block if queue is empty
// remember to free the queueBlock afterwards
t_queueBlock *getQueue(t_queue *queue);