内核驱动的一些技术处理函数

//***********************************************************1./* 工作队列: */step 1)/* 定义和初始化: */static struct workqueue_struct *wq = NULL;static struct work_struct work_delayed;

wq = create_workqueue(“skeleton_dev_wq”)INIT_WORK(&work_delayed, work_queue_func, NULL);static void work_queue_func(struct work_struct *work_wq){}step 2)/* 使用 */queue_delayed_work(wq, &work_delayed, 50)

step 3)/* 注销 */cancel_delayed_work(&work_delayed)destroy_workqueue(wq)

2./* 定时器: */step 1)/* 定义和初始化 */struct timer_list tmr;init_timer(&tmr);tmr.function = TestTimerCallback;static void TestTimerCallback(unsigned long data){}

step 2)/* 使用: */tmr.expires = jiffies + 100add_timer(&tmr)

step 3)/* 注销 */del_timer(&tmr)

3./* tasklet */step 1)/* 定义和初始化 */#include <linux/interrupt.h>//声明一个名叫tasklet_test的tasklet,它的处理函数为tasklet_test_handle()DECLARE_TASKLET(tasklet_test, tasklet_test_handle, 0);static void tasklet_test_handle(unsigned long arg){}step 2)/* 使用 *///调度这个tasklet: 调度一下执行一次tasklet_schedule(&tasklet_test);step 3)/* 注销 *///禁用这个tasklettasklet_kill(&tasklet_test);

4./* wait queue */step 1)/* 定义和初始化 */#include <linux/workqueue.h>static wait_queue_head_t wqChgEvent;init_waitqueue_head(&wqChgEvent);step 2)/* 使用 */wait_event_interruptible_timeout()/* 等待 */wake_up_interruptible(&wqChgEvent)/* 被唤醒 */step 3)/* 注销 */5./* thread */step 1)/* 定义和初始化 */static int test_kernel_thread(void *dummy){}step 2)/* 使用 */kthread_run(test_kernel_thread, chgInfo, “kernel thread test”)step 3)/* 注销 */

//***********************************************************1./* spinlock => 死等,不会引起进程间切换 */step 1)/* 定义和初始化 */static spinlock_t lockEvent;step 2)/* 使用 */spin_lock_irqsave(&lockEvent, flags)// 临界资源: 如一个变量spin_unlock_irqrestore(lockEvent, flagsstep 3)/* 注销 */

2./* semaphore => 可能引起进程间切换 */step 1)/* 定义和初始化 */#include <linux/semaphore.h>step 2)/* 使用 */up()// 临界资源down()step 3)/* 注销 */

哪里会顾得上这些。等到时间将矛盾一层层降解为流言是非误解过结

内核驱动的一些技术处理函数

相关文章:

你感兴趣的文章:

标签云: