completion.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef __LINUX_COMPLETION_H
  2. #define __LINUX_COMPLETION_H
  3. /*
  4. * (C) Copyright 2001 Linus Torvalds
  5. *
  6. * Atomic wait-for-completion handler data structures.
  7. * See kernel/sched.c for details.
  8. */
  9. #include <linux/wait.h>
  10. struct completion {
  11. unsigned int done;
  12. wait_queue_head_t wait;
  13. };
  14. #define COMPLETION_INITIALIZER(work) \
  15. { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
  16. #define COMPLETION_INITIALIZER_ONSTACK(work) \
  17. ({ init_completion(&work); work; })
  18. #define DECLARE_COMPLETION(work) \
  19. struct completion work = COMPLETION_INITIALIZER(work)
  20. /*
  21. * Lockdep needs to run a non-constant initializer for on-stack
  22. * completions - so we use the _ONSTACK() variant for those that
  23. * are on the kernel stack:
  24. */
  25. #ifdef CONFIG_LOCKDEP
  26. # define DECLARE_COMPLETION_ONSTACK(work) \
  27. struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
  28. #else
  29. # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
  30. #endif
  31. static inline void init_completion(struct completion *x)
  32. {
  33. x->done = 0;
  34. init_waitqueue_head(&x->wait);
  35. }
  36. extern void FASTCALL(wait_for_completion(struct completion *));
  37. extern int FASTCALL(wait_for_completion_interruptible(struct completion *x));
  38. extern unsigned long FASTCALL(wait_for_completion_timeout(struct completion *x,
  39. unsigned long timeout));
  40. extern unsigned long FASTCALL(wait_for_completion_interruptible_timeout(
  41. struct completion *x, unsigned long timeout));
  42. extern void FASTCALL(complete(struct completion *));
  43. extern void FASTCALL(complete_all(struct completion *));
  44. #define INIT_COMPLETION(x) ((x).done = 0)
  45. #endif