wait queue

1. Makefile

2. workQueue.c  (如果kernel module名字是workqueue, 会引起问题)



KVERSION = $(shell uname -r)
obj-m = workQueue.o


all:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean#ifndef __KERNEL__
#  define __KERNEL__
#endif
#ifndef MODULE
#  define MODULE
#endif

/*
 * Copyright (C) 2016,2017 Fernando Vanyo Garcia
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *      Fernando Vanyo Garcia 
   
   
    
    
 *      Mi Shuang             
    
    
     
     
 */

#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             #define AUTHOR "Mi Shuang 
            
              " #define DESC "Simple example of kernel Work Queues" MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR(AUTHOR); MODULE_DESCRIPTION(DESC); struct work_ent { struct work_struct real_work; struct delayed_work timeout_work; int arg; } work_ent; static void thread_function(struct work_struct *work); struct work_ent *test_wq; static void thread_function(struct work_struct *work_arg) { struct delayed_work *dwork = container_of(work_arg, struct delayed_work, work); struct work_ent *ent = container_of(dwork, struct work_ent, timeout_work); printk(KERN_INFO "%s: the data is: %d\n", __func__, ent->arg); schedule_delayed_work(&ent->timeout_work, HZ); return; } static int __init entry_point(void) { test_wq = kmalloc(sizeof(*test_wq), GFP_KERNEL); INIT_DELAYED_WORK(&test_wq->timeout_work, thread_function); test_wq->arg = 1000; schedule_delayed_work(&test_wq->timeout_work, HZ); return 0; } static void __exit exit_point(void) { //just in case: flush_delayed_work(&test_wq->timeout_work); cancel_delayed_work(&test_wq->timeout_work); kfree(test_wq); return; } module_init(entry_point); module_exit(exit_point); 
             
            
           
          
         
       
      
      
     
     
    
    
   
   




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值