completion.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 DECLARE_COMPLETION(work) \
  17. struct completion work = COMPLETION_INITIALIZER(work)
  18. /*
  19. * Lockdep needs to run a non-constant initializer for on-stack
  20. * completions - so we use the _ONSTACK() variant for those that
  21. * are on the kernel stack:
  22. */
  23. #ifdef CONFIG_LOCKDEP
  24. # define DECLARE_COMPLETION_ONSTACK(work) \
  25. struct completion work = ({ init_completion(&work); work; })
  26. #else
  27. # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
  28. #endif
  29. static inline void init_completion(struct completion *x)
  30. {
  31. x->done = 0;
  32. init_waitqueue_head(&x->wait);
  33. }
  34. extern void FASTCALL(wait_for_completion(struct completion *));
  35. extern int FASTCALL(wait_for_completion_interruptible(struct completion *x));
  36. extern unsigned long FASTCALL(wait_for_completion_timeout(struct completion *x,
  37. unsigned long timeout));
  38. extern unsigned long FASTCALL(wait_for_completion_interruptible_timeout(
  39. struct completion *x, unsigned long timeout));
  40. extern void FASTCALL(complete(struct completion *));
  41. extern void FASTCALL(complete_all(struct completion *));
  42. #define INIT_COMPLETION(x) ((x).done = 0)
  43. #endif