-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletion.h
More file actions
executable file
·52 lines (41 loc) · 1.26 KB
/
Copy pathcompletion.h
File metadata and controls
executable file
·52 lines (41 loc) · 1.26 KB
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 PFS_LIB_COMPLETION_H
#define PFS_LIB_COMPLETION_H
#include "llist.h"
#include "stdbool.h"
#include <pthread.h>
#ifdef __cplusplus
extern "C" {
#endif
struct completion {
unsigned int done;
pthread_mutex_t lock;
pthread_cond_t cond;
struct list_head list;
};
#define util_init_completion(x) __util_init_completion(x)
static inline void __util_init_completion(struct completion *x)
{
x->done = 0;
pthread_mutex_init(&x->lock, NULL);
pthread_cond_init(&x->cond, NULL);
INIT_LIST_HEAD(&x->list);
}
static inline void util_reinit_completion(struct completion *x)
{
x->done = 0;
}
#define COMPLETION_INITIALIZER(work) \
{ 0, PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, LLIST_HEAD_VALUE(work.list) }
#define DECLARE_COMPLETION(work) \
struct completion work = COMPLETION_INITIALIZER(work)
void util_wait_for_completion(struct completion *);
bool util_try_wait_for_completion(struct completion *x);
unsigned long util_wait_for_completion_timeout(struct completion *x,
unsigned long timeout);
bool util_completion_done(struct completion *x);
void util_complete(struct completion *);
void util_complete_all(struct completion *);
#ifdef __cplusplus
}
#endif
#endif /* PFS_LIB_COMPLETION_H */