From 2a637b2bfb82ef0c4df85b45f531de131d6e5d7a Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Thu, 20 May 2010 18:37:48 -0400 Subject: [PATCH 1/1] Use timer to print our default greeting. --- hellochar.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hellochar.c b/hellochar.c index 3830a47..938b32f 100644 --- a/hellochar.c +++ b/hellochar.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include MODULE_LICENSE("GPL"); @@ -36,14 +36,21 @@ static int hello_open(struct inode *ino, struct file *fp) return 0; } +static void hello_world(unsigned long greeting) +{ + printk(KERN_INFO "%s", (char *) greeting); +} + +static struct timer_list hello_timer; static ssize_t hello_read(struct file *fp, char __user *buf, size_t sz, loff_t *pos) { - unsigned long timeout = 5 * HZ; - while (timeout > 0) { - set_current_state(TASK_INTERRUPTIBLE); - timeout = schedule_timeout(timeout); - } + printk(KERN_INFO "Adding timer...\n"); + init_timer(&hello_timer); + hello_timer.expires = jiffies + 5 * HZ; + hello_timer.function = hello_world; + hello_timer.data = (unsigned long) default_greeting; + add_timer(&hello_timer); return 0; } -- 2.20.1