1 #include <common/spinlock.h>
2 #include <common/wait_queue.h>
3 #include <process/process.h>
4 #include <time/sleep.h>
5 #include <time/timer.h>
6 
7 // 永久地设置该completion已经被完成,不会再有进程等待
8 #define COMPLETE_ALL UINT32_MAX
9 
10 struct completion
11 {
12     unsigned int done;
13     wait_queue_head_t wait_queue;
14 };
15 
16 #define DECLARE_COMPLETION_ON_STACK(name) \
17     struct completion name = {0};         \
18     completion_init(&name);
19 
20 /**
21  * 对外函数声明
22  */
23 void completion_init(struct completion *x);
24 void complete(struct completion *x);
25 void complete_all(struct completion *x);
26 void wait_for_completion(struct completion *x);
27 long wait_for_completion_timeout(struct completion *x, long timeout);
28 void wait_for_completion_interruptible(struct completion *x);
29 long wait_for_completion_interruptible_timeout(struct completion *x, long timeout);
30 void wait_for_multicompletion(struct completion x[], int n);
31 bool try_wait_for_completion(struct completion *x);
32 bool completion_done(struct completion *x);
33 
34 /**
35  * 测试函数声明 (测试代码辅助函数)
36  */
37 struct __test_data
38 {
39     int id;
40     struct completion *one_to_one;
41     struct completion *one_to_many;
42     struct completion *many_to_one;
43 };
44 
45 int __test_completion_waiter(void *data); // 等待者
46 int __test_completion_worker(void *data); // 执行者
47 void __test_completion();