提交 f991b318 编写于 作者: T Tejun Heo

workqueue: clean up delayed_work initializers and add missing one

Reimplement delayed_work initializers using new timer initializers
which take timer flags.  This reduces code duplications and will ease
further initializer changes.  This patch also adds a missing
initializer - INIT_DEFERRABLE_WORK_ONSTACK().
Signed-off-by: NTejun Heo <tj@kernel.org>
上级 203b42f7
...@@ -133,26 +133,20 @@ struct execute_work { ...@@ -133,26 +133,20 @@ struct execute_work {
__WORK_INIT_LOCKDEP_MAP(#n, &(n)) \ __WORK_INIT_LOCKDEP_MAP(#n, &(n)) \
} }
#define __DELAYED_WORK_INITIALIZER(n, f) { \ #define __DELAYED_WORK_INITIALIZER(n, f, tflags) { \
.work = __WORK_INITIALIZER((n).work, (f)), \ .work = __WORK_INITIALIZER((n).work, (f)), \
.timer = TIMER_INITIALIZER(delayed_work_timer_fn, \ .timer = __TIMER_INITIALIZER(delayed_work_timer_fn, \
0, (unsigned long)&(n)), \ 0, (unsigned long)&(n), (tflags)), \
}
#define __DEFERRABLE_WORK_INITIALIZER(n, f) { \
.work = __WORK_INITIALIZER((n).work, (f)), \
.timer = TIMER_DEFERRED_INITIALIZER(delayed_work_timer_fn, \
0, (unsigned long)&(n)), \
} }
#define DECLARE_WORK(n, f) \ #define DECLARE_WORK(n, f) \
struct work_struct n = __WORK_INITIALIZER(n, f) struct work_struct n = __WORK_INITIALIZER(n, f)
#define DECLARE_DELAYED_WORK(n, f) \ #define DECLARE_DELAYED_WORK(n, f) \
struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f) struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, 0)
#define DECLARE_DEFERRABLE_WORK(n, f) \ #define DECLARE_DEFERRABLE_WORK(n, f) \
struct delayed_work n = __DEFERRABLE_WORK_INITIALIZER(n, f) struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, TIMER_DEFERRABLE)
/* /*
* initialize a work item's function pointer * initialize a work item's function pointer
...@@ -216,29 +210,33 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; } ...@@ -216,29 +210,33 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
__INIT_WORK((_work), (_func), 1); \ __INIT_WORK((_work), (_func), 1); \
} while (0) } while (0)
#define INIT_DELAYED_WORK(_work, _func) \ #define __INIT_DELAYED_WORK(_work, _func, _tflags) \
do { \ do { \
INIT_WORK(&(_work)->work, (_func)); \ INIT_WORK(&(_work)->work, (_func)); \
init_timer(&(_work)->timer); \ __setup_timer(&(_work)->timer, delayed_work_timer_fn, \
(_work)->timer.function = delayed_work_timer_fn; \ (unsigned long)(_work), (_tflags)); \
(_work)->timer.data = (unsigned long)(_work); \
} while (0) } while (0)
#define INIT_DELAYED_WORK_ONSTACK(_work, _func) \ #define __INIT_DELAYED_WORK_ONSTACK(_work, _func, _tflags) \
do { \ do { \
INIT_WORK_ONSTACK(&(_work)->work, (_func)); \ INIT_WORK_ONSTACK(&(_work)->work, (_func)); \
init_timer_on_stack(&(_work)->timer); \ __setup_timer_on_stack(&(_work)->timer, \
(_work)->timer.function = delayed_work_timer_fn; \ delayed_work_timer_fn, \
(_work)->timer.data = (unsigned long)(_work); \ (unsigned long)(_work), \
(_tflags)); \
} while (0) } while (0)
#define INIT_DELAYED_WORK(_work, _func) \
__INIT_DELAYED_WORK(_work, _func, 0)
#define INIT_DELAYED_WORK_ONSTACK(_work, _func) \
__INIT_DELAYED_WORK_ONSTACK(_work, _func, 0)
#define INIT_DEFERRABLE_WORK(_work, _func) \ #define INIT_DEFERRABLE_WORK(_work, _func) \
do { \ __INIT_DELAYED_WORK(_work, _func, TIMER_DEFERRABLE)
INIT_WORK(&(_work)->work, (_func)); \
init_timer_deferrable(&(_work)->timer); \ #define INIT_DEFERRABLE_WORK_ONSTACK(_work, _func) \
(_work)->timer.function = delayed_work_timer_fn; \ __INIT_DELAYED_WORK_ONSTACK(_work, _func, TIMER_DEFERRABLE)
(_work)->timer.data = (unsigned long)(_work); \
} while (0)
/** /**
* work_pending - Find out whether a work item is currently pending * work_pending - Find out whether a work item is currently pending
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册