Linux驅動開發之中斷處理

參考

內核線程同步之signal

tasklet

軟中斷中執行,當tasklet在執行的時候,不會重複進入。

worker工作隊列

可重複進入。

內核線程

內核線程函數體常用循環控制條件,其中signal_pending用來接收kill -SIGKILL <pid>kthread_should_stop用來接收kthread_stop

#include <linux/module.h>
#include <linux/kthread.h>
#include <linux/delay.h>

static struct task_struct * slam_thread = NULL;
static int is_signal_exited = 0;

static int func(void *data) 
{
    allow_signal(SIGKILL);
    mdelay(1000);
	while(!signal_pending(current) && !kthread_should_stop()) {
	    set_current_state(TASK_INTERRUPTIBLE);
	    schedule_timeout(msecs_to_jiffies(5000));
	}
	is_signal_exited = 1;
	return 0;
}
static __init int kthread_signal_example_init(void)
{
        slam_thread = kthread_run(func, NULL, "slam");
        return 0;
}
static __exit void kthread_signal_example_exit(void)
{
    if(!is_signal_exited && !IS_ERR(slam_thread))
        kthread_stop(slam_thread);
}
module_init(kthread_signal_example_init);
module_exit(kthread_signal_example_exit);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章