completion.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_COMPLETION_H
  3. #define __LINUX_COMPLETION_H
  4. /*
  5. * (C) Copyright 2001 Linus Torvalds
  6. *
  7. * Atomic wait-for-completion handler data structures.
  8. * See kernel/sched/completion.c for details.
  9. */
  10. #ifndef __UBOOT__
  11. #include <linux/wait.h>
  12. #endif /* __UBOOT__ */
  13. /*
  14. * struct completion - structure used to maintain state for a "completion"
  15. *
  16. * This is the opaque structure used to maintain the state for a "completion".
  17. * Completions currently use a FIFO to queue threads that have to wait for
  18. * the "completion" event.
  19. *
  20. * See also: complete(), wait_for_completion() (and friends _timeout,
  21. * _interruptible, _interruptible_timeout, and _killable), init_completion(),
  22. * reinit_completion(), and macros DECLARE_COMPLETION(),
  23. * DECLARE_COMPLETION_ONSTACK().
  24. */
  25. struct completion {
  26. unsigned int done;
  27. #ifndef __UBOOT__
  28. wait_queue_head_t wait;
  29. #endif /* __UBOOT__ */
  30. };
  31. #define init_completion_map(x, m) __init_completion(x)
  32. #define init_completion(x) __init_completion(x)
  33. static inline void complete_acquire(struct completion *x) {}
  34. static inline void complete_release(struct completion *x) {}
  35. #define COMPLETION_INITIALIZER(work) \
  36. { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
  37. #define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \
  38. (*({ init_completion_map(&(work), &(map)); &(work); }))
  39. #define COMPLETION_INITIALIZER_ONSTACK(work) \
  40. (*({ init_completion(&work); &work; }))
  41. /**
  42. * DECLARE_COMPLETION - declare and initialize a completion structure
  43. * @work: identifier for the completion structure
  44. *
  45. * This macro declares and initializes a completion structure. Generally used
  46. * for static declarations. You should use the _ONSTACK variant for automatic
  47. * variables.
  48. */
  49. #define DECLARE_COMPLETION(work) \
  50. struct completion work = COMPLETION_INITIALIZER(work)
  51. /*
  52. * Lockdep needs to run a non-constant initializer for on-stack
  53. * completions - so we use the _ONSTACK() variant for those that
  54. * are on the kernel stack:
  55. */
  56. /**
  57. * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure
  58. * @work: identifier for the completion structure
  59. *
  60. * This macro declares and initializes a completion structure on the kernel
  61. * stack.
  62. */
  63. #ifdef CONFIG_LOCKDEP
  64. # define DECLARE_COMPLETION_ONSTACK(work) \
  65. struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
  66. # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) \
  67. struct completion work = COMPLETION_INITIALIZER_ONSTACK_MAP(work, map)
  68. #else
  69. # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
  70. # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) DECLARE_COMPLETION(work)
  71. #endif
  72. /**
  73. * init_completion - Initialize a dynamically allocated completion
  74. * @x: pointer to completion structure that is to be initialized
  75. *
  76. * This inline function will initialize a dynamically created completion
  77. * structure.
  78. */
  79. static inline void __init_completion(struct completion *x)
  80. {
  81. x->done = 0;
  82. #ifndef __UBOOT__
  83. init_waitqueue_head(&x->wait);
  84. #endif /* __UBOOT__ */
  85. }
  86. /**
  87. * reinit_completion - reinitialize a completion structure
  88. * @x: pointer to completion structure that is to be reinitialized
  89. *
  90. * This inline function should be used to reinitialize a completion structure so it can
  91. * be reused. This is especially important after complete_all() is used.
  92. */
  93. static inline void reinit_completion(struct completion *x)
  94. {
  95. x->done = 0;
  96. }
  97. #ifndef __UBOOT__
  98. extern void wait_for_completion(struct completion *);
  99. extern void wait_for_completion_io(struct completion *);
  100. extern int wait_for_completion_interruptible(struct completion *x);
  101. extern int wait_for_completion_killable(struct completion *x);
  102. extern unsigned long wait_for_completion_timeout(struct completion *x,
  103. unsigned long timeout);
  104. extern unsigned long wait_for_completion_io_timeout(struct completion *x,
  105. unsigned long timeout);
  106. extern long wait_for_completion_interruptible_timeout(
  107. struct completion *x, unsigned long timeout);
  108. extern long wait_for_completion_killable_timeout(
  109. struct completion *x, unsigned long timeout);
  110. extern bool try_wait_for_completion(struct completion *x);
  111. extern bool completion_done(struct completion *x);
  112. extern void complete(struct completion *);
  113. extern void complete_all(struct completion *);
  114. #else /* __UBOOT __ */
  115. #define wait_for_completion(x) do {} while (0)
  116. #define wait_for_completion_io(x) do {} while (0)
  117. inline int wait_for_completion_interruptible(struct completion *x)
  118. {
  119. return 1;
  120. }
  121. inline int wait_for_completion_killable(struct completion *x)
  122. {
  123. return 1;
  124. }
  125. inline unsigned long wait_for_completion_timeout(struct completion *x,
  126. unsigned long timeout)
  127. {
  128. return 1;
  129. }
  130. inline unsigned long wait_for_completion_io_timeout(struct completion *x,
  131. unsigned long timeout)
  132. {
  133. return 1;
  134. }
  135. inline long wait_for_completion_interruptible_timeout(struct completion *x,
  136. unsigned long timeout)
  137. {
  138. return 1;
  139. }
  140. inline long wait_for_completion_killable_timeout(struct completion *x,
  141. unsigned long timeout)
  142. {
  143. return 1;
  144. }
  145. inline bool try_wait_for_completion(struct completion *x)
  146. {
  147. return 1;
  148. }
  149. inline bool completion_done(struct completion *x)
  150. {
  151. return 1;
  152. }
  153. #define complete(x) do {} while (0)
  154. #define complete_all(x) do {} while (0)
  155. #endif /* __UBOOT__ */
  156. #endif