workqueue.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * workqueue.h --- work queue handling for Linux.
  3. */
  4. #ifndef _LINUX_WORKQUEUE_H
  5. #define _LINUX_WORKQUEUE_H
  6. #include <linux/timer.h>
  7. #include <linux/linkage.h>
  8. #include <linux/bitops.h>
  9. struct workqueue_struct;
  10. struct work_struct {
  11. unsigned long pending;
  12. struct list_head entry;
  13. void (*func)(void *);
  14. void *data;
  15. void *wq_data;
  16. };
  17. struct delayed_work {
  18. struct work_struct work;
  19. struct timer_list timer;
  20. };
  21. struct execute_work {
  22. struct work_struct work;
  23. };
  24. #define __WORK_INITIALIZER(n, f, d) { \
  25. .entry = { &(n).entry, &(n).entry }, \
  26. .func = (f), \
  27. .data = (d), \
  28. }
  29. #define __DELAYED_WORK_INITIALIZER(n, f, d) { \
  30. .work = __WORK_INITIALIZER((n).work, (f), (d)), \
  31. .timer = TIMER_INITIALIZER(NULL, 0, 0), \
  32. }
  33. #define DECLARE_WORK(n, f, d) \
  34. struct work_struct n = __WORK_INITIALIZER(n, f, d)
  35. #define DECLARE_DELAYED_WORK(n, f, d) \
  36. struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, d)
  37. /*
  38. * initialize a work item's function and data pointers
  39. */
  40. #define PREPARE_WORK(_work, _func, _data) \
  41. do { \
  42. (_work)->func = (_func); \
  43. (_work)->data = (_data); \
  44. } while (0)
  45. #define PREPARE_DELAYED_WORK(_work, _func, _data) \
  46. PREPARE_WORK(&(_work)->work, (_func), (_data))
  47. /*
  48. * initialize all of a work item in one go
  49. */
  50. #define INIT_WORK(_work, _func, _data) \
  51. do { \
  52. INIT_LIST_HEAD(&(_work)->entry); \
  53. (_work)->pending = 0; \
  54. PREPARE_WORK((_work), (_func), (_data)); \
  55. } while (0)
  56. #define INIT_DELAYED_WORK(_work, _func, _data) \
  57. do { \
  58. INIT_WORK(&(_work)->work, (_func), (_data)); \
  59. init_timer(&(_work)->timer); \
  60. } while (0)
  61. extern struct workqueue_struct *__create_workqueue(const char *name,
  62. int singlethread);
  63. #define create_workqueue(name) __create_workqueue((name), 0)
  64. #define create_singlethread_workqueue(name) __create_workqueue((name), 1)
  65. extern void destroy_workqueue(struct workqueue_struct *wq);
  66. extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work));
  67. extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay));
  68. extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
  69. struct delayed_work *work, unsigned long delay);
  70. extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq));
  71. extern int FASTCALL(schedule_work(struct work_struct *work));
  72. extern int FASTCALL(schedule_delayed_work(struct delayed_work *work, unsigned long delay));
  73. extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, unsigned long delay);
  74. extern int schedule_on_each_cpu(void (*func)(void *info), void *info);
  75. extern void flush_scheduled_work(void);
  76. extern int current_is_keventd(void);
  77. extern int keventd_up(void);
  78. extern void init_workqueues(void);
  79. void cancel_rearming_delayed_work(struct delayed_work *work);
  80. void cancel_rearming_delayed_workqueue(struct workqueue_struct *,
  81. struct delayed_work *);
  82. int execute_in_process_context(void (*fn)(void *), void *,
  83. struct execute_work *);
  84. /*
  85. * Kill off a pending schedule_delayed_work(). Note that the work callback
  86. * function may still be running on return from cancel_delayed_work(). Run
  87. * flush_scheduled_work() to wait on it.
  88. */
  89. static inline int cancel_delayed_work(struct delayed_work *work)
  90. {
  91. int ret;
  92. ret = del_timer_sync(&work->timer);
  93. if (ret)
  94. clear_bit(0, &work->work.pending);
  95. return ret;
  96. }
  97. #endif