blob: 2843fb9d145e4d2bbd689b4c3dffefda6af278cb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#ifndef TASK_QUEUE_H_
#define TASK_QUEUE_H_
#include <pthread.h>
typedef void (*TaskFn)(void *arg);
typedef struct {
TaskFn *tasks;
void **args;
int capacity;
int front;
int end;
int size;
pthread_mutex_t lock;
pthread_cond_t not_full;
pthread_cond_t not_empty;
} TaskQueue;
void TaskQueue_init(TaskQueue *self, int capacity);
void TaskQueue_destroy(TaskQueue *self);
void TaskQueue_push(TaskQueue *self, TaskFn task, void *arg);
void TaskQueue_pop(TaskQueue *self, TaskFn *task, void **arg);
#endif
|