workqueue.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. struct timer_list timer;
  17. };
  18. struct execute_work {
  19. struct work_struct work;
  20. };
  21. #define __WORK_INITIALIZER(n, f, d) { \
  22. .entry = { &(n).entry, &(n).entry }, \
  23. .func = (f), \
  24. .data = (d), \
  25. .timer = TIMER_INITIALIZER(NULL, 0, 0), \
  26. }
  27. #define DECLARE_WORK(n, f, d) \
  28. struct work_struct n = __WORK_INITIALIZER(n, f, d)
  29. /*
  30. * initialize a work-struct's func and data pointers:
  31. */
  32. #define PREPARE_WORK(_work, _func, _data) \
  33. do { \
  34. (_work)->func = _func; \
  35. (_work)->data = _data; \
  36. } while (0)
  37. /*
  38. * initialize all of a work-struct:
  39. */
  40. #define INIT_WORK(_work, _func, _data) \
  41. do { \
  42. INIT_LIST_HEAD(&(_work)->entry); \
  43. (_work)->pending = 0; \
  44. PREPARE_WORK((_work), (_func), (_data)); \
  45. init_timer(&(_work)->timer); \
  46. } while (0)
  47. extern struct workqueue_struct *__create_workqueue(const char *name,
  48. int singlethread);
  49. #define create_workqueue(name) __create_workqueue((name), 0)
  50. #define create_singlethread_workqueue(name) __create_workqueue((name), 1)
  51. extern void destroy_workqueue(struct workqueue_struct *wq);
  52. extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work));
  53. extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct work_struct *work, unsigned long delay));
  54. extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
  55. struct work_struct *work, unsigned long delay);
  56. extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq));
  57. extern int FASTCALL(schedule_work(struct work_struct *work));
  58. extern int FASTCALL(schedule_delayed_work(struct work_struct *work, unsigned long delay));
  59. extern int schedule_delayed_work_on(int cpu, struct work_struct *work, unsigned long delay);
  60. extern int schedule_on_each_cpu(void (*func)(void *info), void *info);
  61. extern void flush_scheduled_work(void);
  62. extern int current_is_keventd(void);
  63. extern int keventd_up(void);
  64. extern void init_workqueues(void);
  65. void cancel_rearming_delayed_work(struct work_struct *work);
  66. void cancel_rearming_delayed_workqueue(struct workqueue_struct *,
  67. struct work_struct *);
  68. int execute_in_process_context(void (*fn)(void *), void *,
  69. struct execute_work *);
  70. /*
  71. * Kill off a pending schedule_delayed_work(). Note that the work callback
  72. * function may still be running on return from cancel_delayed_work(). Run
  73. * flush_scheduled_work() to wait on it.
  74. */
  75. static inline int cancel_delayed_work(struct work_struct *work)
  76. {
  77. int ret;
  78. ret = del_timer_sync(&work->timer);
  79. if (ret)
  80. clear_bit(0, &work->pending);
  81. return ret;
  82. }
  83. #endif