forked from sheepdog/sheepdog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork.h
52 lines (37 loc) · 1.04 KB
/
work.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef __WORK_H__
#define __WORK_H__
#include <stdbool.h>
struct work;
struct work_queue;
typedef void (*work_func_t)(struct work *);
struct work {
struct list_head w_list;
work_func_t fn;
work_func_t done;
};
struct work_queue {
int wq_state;
struct list_head pending_list;
};
struct worker_info {
const char *name;
struct list_head worker_info_siblings;
bool ordered;
pthread_mutex_t finished_lock;
struct list_head finished_list;
/* wokers sleep on this and signaled by tgtd */
pthread_cond_t pending_cond;
/* locked by tgtd and workers */
pthread_mutex_t pending_lock;
/* protected by pending_lock */
struct work_queue q;
pthread_mutex_t startup_lock;
pthread_t worker_thread; /* used for an ordered work queue */
};
extern struct list_head worker_info_list;
extern int total_ordered_workers;
/* if 'ordered' is true, the work queue are processes in order. */
struct work_queue *init_work_queue(const char *name, bool ordered);
void queue_work(struct work_queue *q, struct work *work);
int init_wqueue_eventfd(void);
#endif