wake_q.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef _LINUX_SCHED_WAKE_Q_H
  2. #define _LINUX_SCHED_WAKE_Q_H
  3. /*
  4. * Wake-queues are lists of tasks with a pending wakeup, whose
  5. * callers have already marked the task as woken internally,
  6. * and can thus carry on. A common use case is being able to
  7. * do the wakeups once the corresponding user lock as been
  8. * released.
  9. *
  10. * We hold reference to each task in the list across the wakeup,
  11. * thus guaranteeing that the memory is still valid by the time
  12. * the actual wakeups are performed in wake_up_q().
  13. *
  14. * One per task suffices, because there's never a need for a task to be
  15. * in two wake queues simultaneously; it is forbidden to abandon a task
  16. * in a wake queue (a call to wake_up_q() _must_ follow), so if a task is
  17. * already in a wake queue, the wakeup will happen soon and the second
  18. * waker can just skip it.
  19. *
  20. * The DEFINE_WAKE_Q macro declares and initializes the list head.
  21. * wake_up_q() does NOT reinitialize the list; it's expected to be
  22. * called near the end of a function. Otherwise, the list can be
  23. * re-initialized for later re-use by wake_q_init().
  24. *
  25. * Note that this can cause spurious wakeups. schedule() callers
  26. * must ensure the call is done inside a loop, confirming that the
  27. * wakeup condition has in fact occurred.
  28. */
  29. #include <linux/sched.h>
  30. struct wake_q_head {
  31. struct wake_q_node *first;
  32. struct wake_q_node **lastp;
  33. };
  34. #define WAKE_Q_TAIL ((struct wake_q_node *) 0x01)
  35. #define DEFINE_WAKE_Q(name) \
  36. struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
  37. static inline void wake_q_init(struct wake_q_head *head)
  38. {
  39. head->first = WAKE_Q_TAIL;
  40. head->lastp = &head->first;
  41. }
  42. extern void wake_q_add(struct wake_q_head *head,
  43. struct task_struct *task);
  44. extern void wake_up_q(struct wake_q_head *head);
  45. #endif /* _LINUX_SCHED_WAKE_Q_H */