workqueue.h 2.6 KB

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