mirror of
https://github.com/Hizenberg469/MultiThreading_Part_A.git
synced 2026-04-20 02:22:23 +03:00
ProducerConsumer with cv and mutex
This commit is contained in:
35
ProducerConsumerProblem/queue/queue.h
Normal file
35
ProducerConsumerProblem/queue/queue.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef __QUEUE__
|
||||
#define __QUEUE__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define Q_DEFAULT_SIZE 5
|
||||
struct Queue_t {
|
||||
void* elem[Q_DEFAULT_SIZE];
|
||||
unsigned int front;
|
||||
unsigned int rear;
|
||||
unsigned int count;
|
||||
pthread_mutex_t q_mutex;
|
||||
pthread_cond_t q_cv;
|
||||
};
|
||||
|
||||
struct Queue_t* initQ(void);
|
||||
|
||||
bool
|
||||
is_queue_empty(struct Queue_t* q);
|
||||
|
||||
bool
|
||||
is_queue_full(struct Queue_t* q);
|
||||
|
||||
bool
|
||||
enqueue(struct Queue_t* q, void* ptr);
|
||||
|
||||
void*
|
||||
deque(struct Queue_t* q);
|
||||
|
||||
void
|
||||
print_Queue(struct Queue_t* q);
|
||||
|
||||
#define Q_COUNT(q) (q->count)
|
||||
#endif
|
||||
Reference in New Issue
Block a user