xref: /openbmc/linux/include/linux/completion.h (revision be4de352)
11da177e4SLinus Torvalds #ifndef __LINUX_COMPLETION_H
21da177e4SLinus Torvalds #define __LINUX_COMPLETION_H
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds /*
51da177e4SLinus Torvalds  * (C) Copyright 2001 Linus Torvalds
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * Atomic wait-for-completion handler data structures.
81da177e4SLinus Torvalds  * See kernel/sched.c for details.
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds #include <linux/wait.h>
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds struct completion {
141da177e4SLinus Torvalds 	unsigned int done;
151da177e4SLinus Torvalds 	wait_queue_head_t wait;
161da177e4SLinus Torvalds };
171da177e4SLinus Torvalds 
181da177e4SLinus Torvalds #define COMPLETION_INITIALIZER(work) \
191da177e4SLinus Torvalds 	{ 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
201da177e4SLinus Torvalds 
21f86bf9b7SIngo Molnar #define COMPLETION_INITIALIZER_ONSTACK(work) \
22f86bf9b7SIngo Molnar 	({ init_completion(&work); work; })
23f86bf9b7SIngo Molnar 
241da177e4SLinus Torvalds #define DECLARE_COMPLETION(work) \
251da177e4SLinus Torvalds 	struct completion work = COMPLETION_INITIALIZER(work)
261da177e4SLinus Torvalds 
278b3db9c5SIngo Molnar /*
288b3db9c5SIngo Molnar  * Lockdep needs to run a non-constant initializer for on-stack
298b3db9c5SIngo Molnar  * completions - so we use the _ONSTACK() variant for those that
308b3db9c5SIngo Molnar  * are on the kernel stack:
318b3db9c5SIngo Molnar  */
328b3db9c5SIngo Molnar #ifdef CONFIG_LOCKDEP
338b3db9c5SIngo Molnar # define DECLARE_COMPLETION_ONSTACK(work) \
34f86bf9b7SIngo Molnar 	struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
358b3db9c5SIngo Molnar #else
368b3db9c5SIngo Molnar # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
378b3db9c5SIngo Molnar #endif
388b3db9c5SIngo Molnar 
391da177e4SLinus Torvalds static inline void init_completion(struct completion *x)
401da177e4SLinus Torvalds {
411da177e4SLinus Torvalds 	x->done = 0;
421da177e4SLinus Torvalds 	init_waitqueue_head(&x->wait);
431da177e4SLinus Torvalds }
441da177e4SLinus Torvalds 
45b15136e9SIngo Molnar extern void wait_for_completion(struct completion *);
46b15136e9SIngo Molnar extern int wait_for_completion_interruptible(struct completion *x);
47009e577eSMatthew Wilcox extern int wait_for_completion_killable(struct completion *x);
48b15136e9SIngo Molnar extern unsigned long wait_for_completion_timeout(struct completion *x,
49b15136e9SIngo Molnar 						   unsigned long timeout);
50b15136e9SIngo Molnar extern unsigned long wait_for_completion_interruptible_timeout(
51b15136e9SIngo Molnar 			struct completion *x, unsigned long timeout);
52be4de352SDave Chinner extern bool try_wait_for_completion(struct completion *x);
53be4de352SDave Chinner extern bool completion_done(struct completion *x);
541da177e4SLinus Torvalds 
55b15136e9SIngo Molnar extern void complete(struct completion *);
56b15136e9SIngo Molnar extern void complete_all(struct completion *);
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds #define INIT_COMPLETION(x)	((x).done = 0)
591da177e4SLinus Torvalds 
6039d2f1abSDavid Chinner 
611da177e4SLinus Torvalds #endif
62