Use timer to print our default greeting.
[cascardo/kernel/samples/char2/.git] / hellochar.c
index c3f26dc..938b32f 100644 (file)
@@ -21,7 +21,7 @@
 #include <linux/cdev.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
-#include <linux/sched.h>
+#include <linux/timer.h>
 
 MODULE_LICENSE("GPL");
 
@@ -36,12 +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 expire = jiffies + 5 * HZ;
-       while (time_after(expire, jiffies))
-               schedule();
+       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;
 }