LDD3 tasklet 使用

tasklet機制及API註解就不寫了,測試代碼如下:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/fs.h>
#include <linux/kdev_t.h>
#include <linux/cdev.h>
#include <linux/kernel.h>
#include <linux/interrupt.h> 

#define switch 0//是否使用宏定義
void tasklets_function(unsigned long sign);

#if switch
 static DECLARE_TASKLET(my_tasklet,tasklets_function,3);
#else
 static struct tasklet_struct my_tasklet; 
#endif
 void tasklets_function(unsigned long sign)
{
 printk(KERN_EMERG"tasklet out %ld\n",sign);
}
 
static void tasklets_init(void)
{
#if !switch
  tasklet_init(&my_tasklet, tasklets_function, 0);
#endif
  tasklet_schedule(&my_tasklet);
}

static void tasklets_exit(void)
{
 tasklet_kill(&my_tasklet);
 printk(KERN_EMERG"GOOBYE,WORLD\t\n");

}

module_init(tasklets_init);
module_exit(tasklets_exit);
MODULE_LICENSE("Dual BSD/GPL");

 測試方法及結果如下:

[root@localhost tasklet]# insmod tasklet.ko
[root@localhost tasklet]#
Message from syslogd@ at Mon Aug 13 14:19:33 2012 ...
localhost kernel: tasklet out 3
[root@localhost tasklet]#

打開switch開關後:

[root@localhost tasklet]# insmod tasklet.ko
[root@localhost tasklet]#
Message from syslogd@ at Mon Aug 13 14:18:49 2012 ...
localhost kernel: tasklet out 0
[root@localhost tasklet]#

發佈了29 篇原創文章 · 獲贊 19 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章