0001
0002 #ifndef __LINUX_COMPLETION_H
0003 #define __LINUX_COMPLETION_H
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/swait.h>
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 struct completion {
0027 unsigned int done;
0028 struct swait_queue_head wait;
0029 };
0030
0031 #define init_completion_map(x, m) init_completion(x)
0032 static inline void complete_acquire(struct completion *x) {}
0033 static inline void complete_release(struct completion *x) {}
0034
0035 #define COMPLETION_INITIALIZER(work) \
0036 { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
0037
0038 #define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \
0039 (*({ init_completion_map(&(work), &(map)); &(work); }))
0040
0041 #define COMPLETION_INITIALIZER_ONSTACK(work) \
0042 (*({ init_completion(&work); &work; }))
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 #define DECLARE_COMPLETION(work) \
0053 struct completion work = COMPLETION_INITIALIZER(work)
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 #ifdef CONFIG_LOCKDEP
0068 # define DECLARE_COMPLETION_ONSTACK(work) \
0069 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
0070 # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) \
0071 struct completion work = COMPLETION_INITIALIZER_ONSTACK_MAP(work, map)
0072 #else
0073 # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
0074 # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) DECLARE_COMPLETION(work)
0075 #endif
0076
0077
0078
0079
0080
0081
0082
0083
0084 static inline void init_completion(struct completion *x)
0085 {
0086 x->done = 0;
0087 init_swait_queue_head(&x->wait);
0088 }
0089
0090
0091
0092
0093
0094
0095
0096
0097 static inline void reinit_completion(struct completion *x)
0098 {
0099 x->done = 0;
0100 }
0101
0102 extern void wait_for_completion(struct completion *);
0103 extern void wait_for_completion_io(struct completion *);
0104 extern int wait_for_completion_interruptible(struct completion *x);
0105 extern int wait_for_completion_killable(struct completion *x);
0106 extern unsigned long wait_for_completion_timeout(struct completion *x,
0107 unsigned long timeout);
0108 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
0109 unsigned long timeout);
0110 extern long wait_for_completion_interruptible_timeout(
0111 struct completion *x, unsigned long timeout);
0112 extern long wait_for_completion_killable_timeout(
0113 struct completion *x, unsigned long timeout);
0114 extern bool try_wait_for_completion(struct completion *x);
0115 extern bool completion_done(struct completion *x);
0116
0117 extern void complete(struct completion *);
0118 extern void complete_all(struct completion *);
0119
0120 #endif