workqueue.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 void flush_scheduled_work(void);
  56. extern int current_is_keventd(void);
  57. extern int keventd_up(void);
  58. extern void init_workqueues(void);
  59. void cancel_rearming_delayed_work(struct work_struct *work);
  60. void cancel_rearming_delayed_workqueue(struct workqueue_struct *,
  61. struct work_struct *);
  62. /*
  63. * Kill off a pending schedule_delayed_work(). Note that the work callback
  64. * function may still be running on return from cancel_delayed_work(). Run
  65. * flush_scheduled_work() to wait on it.
  66. */
  67. static inline int cancel_delayed_work(struct work_struct *work)
  68. {
  69. int ret;
  70. ret = del_timer_sync(&work->timer);
  71. if (ret)
  72. clear_bit(0, &work->pending);
  73. return ret;
  74. }
  75. #endif