diff options
author | Viresh Kumar <viresh.kumar@linaro.org> | 2013-02-06 12:22:46 +0530 |
---|---|---|
committer | Viresh Kumar <viresh.kumar@linaro.org> | 2013-02-06 12:22:46 +0530 |
commit | e5c58530c1c4745fed0a3398047573667658972c (patch) | |
tree | 0a6a687c2d40269eb40946c6bad053d5a451e7ac | |
parent | 82bc6f123a038c881f21d83ebaf41295a55b8a68 (diff) |
Add delayed-wq
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | delayed-wq.c | 49 |
2 files changed, 50 insertions, 1 deletions
@@ -1,6 +1,6 @@ ifneq ($(KERNELRELEASE),) -obj-m := workqueue.o +obj-m := delayed-wq.o mdelay-workqueue.o workqueue.o else diff --git a/delayed-wq.c b/delayed-wq.c new file mode 100644 index 0000000..d1e5387 --- /dev/null +++ b/delayed-wq.c @@ -0,0 +1,49 @@ +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/timer.h> +#include <linux/module.h> +#include <linux/printk.h> +#include <linux/workqueue.h> + +#define TIMER_DELAY 1 +static struct workqueue_struct *gwq; +static struct delayed_work gwork; + +DECLARE_COMPLETION(wq_complete); +int count=30, done=0; + +static void wq_handler(struct work_struct *work) +{ + while (done++ < count) { + mdelay(70); + queue_delayed_work(gwq, &gwork, 2); + return; + } + complete(&wq_complete); +} + +static int wq_module_init(void) +{ + gwq = alloc_workqueue("wq-test", 0, 0); + if (!gwq) { + pr_err("Failed to allocate workqueue\n"); + return 0; + } + + INIT_DELAYED_WORK(&gwork, wq_handler); + queue_delayed_work(gwq, &gwork, 2); + + wait_for_completion_interruptible(&wq_complete); + return 0; +} +module_init(wq_module_init); + +static void __exit wq_module_exit(void) +{ + destroy_workqueue(gwq); +} +module_exit(wq_module_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>"); +MODULE_DESCRIPTION("Workqueue Analyser"); |