Use timer to print our default greeting. sched
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Thu, 20 May 2010 22:37:48 +0000 (18:37 -0400)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Thu, 20 May 2010 22:37:48 +0000 (18:37 -0400)
hellochar.c

index 3830a47..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,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;
 }