Use tasklet to schedule printing our default greeting.
[cascardo/kernel/samples/char2/.git] / hellochar.c
index 206b6d1..91e8d69 100644 (file)
 #include <linux/cdev.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
+#include <linux/interrupt.h>
 
 MODULE_LICENSE("GPL");
 
 static dev_t devnum;
 static struct cdev *dev;
-static const char default_greeting[] = "Hello, World!\n";
+static const char def_greeting[] = "Hello, World!\n";
 
 static DEFINE_SPINLOCK(hello_lock);
 
@@ -35,14 +36,18 @@ 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 DECLARE_TASKLET(hello_tasklet, hello_world, def_greeting);
+
 static ssize_t hello_read(struct file *fp, char __user *buf, size_t sz,
        loff_t *pos)
 {
-       int i = 1 << 28;
-       spin_lock(&hello_lock);
-       while (i--)
-               cpu_relax();
-       spin_unlock(&hello_lock);
+       printk(KERN_INFO "Scheduling tasklet...\n");
+       tasklet_schedule(&hello_tasklet);
        return 0;
 }
 
@@ -92,6 +97,7 @@ reg_out:
 
 static void __exit ch_exit(void)
 {
+       tasklet_kill(&hello_tasklet);
        cdev_del(dev);
        unregister_chrdev_region(devnum, 256);
 }