linux内核completion实现分析

linux内核completion实现分析

ID:11897479

大小:38.50 KB

页数:3页

时间:2018-07-14

linux内核completion实现分析_第1页
linux内核completion实现分析_第2页
linux内核completion实现分析_第3页
资源描述:

《linux内核completion实现分析》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、Linux内核completion实现分析completion结构及初始化#define__WAITQUEUE_INITIALIZER(name,tsk){.private=tsk,.func=default_wake_function,.task_list={NULL,NULL}}#defineDECLARE_WAITQUEUE(name,tsk)wait_queue_tname=__WAITQUEUE_INITIALIZER(name,tsk)struct__wait_queue{unsignedintflags;#defineWQ_FLAG_EXCLUSIVE0x01vo

2、id*private;wait_queue_func_tfunc;structlist_headtask_list;};structcompletion{unsignedintdone;wait_queue_head_twait;};静态初始化直接使用DECLARE_COMPLETION#defineDECLARE_COMPLETION(work)structcompletionwork=COMPLETION_INITIALIZER(work)#defineCOMPLETION_INITIALIZER(work){0,__WAIT_QUEUE_HEAD_INITIALIZER((w

3、ork).wait)}staticinlinevoidinit_completion(structcompletion*x){x->done=0;init_waitqueue_head(&x->wait);}#defineINIT_COMPLETION(x)((x).done=0)动态创建structcompletionmy_completion;init_completion(&my_completion);completion实现分析completion实现主要依靠spinlock、系统调度schedule、wait_queue,还有一个标志位done。一个completion通常

4、是一个单次设备,也就是说,他在使用一次后会被丢弃。但是如果仔细处理也可以被重复使用。如果没有使用completion_all,则我们可以重复使用一个completion结构,只要那个将要触发的事件是明确而不含糊的,就不会有问题。但是如果使用了completion_all,则必须在重复使用前重新初始化,可以使用宏INIT_COMPLETION完成,此宏把done置零。因为在completion_all中done被赋值成UINT_MAX/2,所有在唤醒所有进程后done也不太可能变成0,为方便下次使用,必须重新初始化。Completion常用函数:voidfastcall__schedwa

5、it_for_completion(structcompletion*x);unsignedlongfastcall__schedwait_for_completion_timeout(structcompletion*x,unsignedlongtimeout);voidfastcallcomplete(structcompletion*x);voidfastcallcomplete_all(structcompletion*x);completion例子:#include#include#include

6、nel.h>/*printk*/#include/*currentandeverything*/#include/*forcompletion*/#include/*forchardev*/staticintcompletion_major=0;ssize_tcompletion_read(structfile*filp,char__user*buf,size_tcount,loff_t*pos);ssize_tcompletion_write(structfile*filp,char__us

7、er*buf,size_tcount,loff_t*pos);DECLARE_COMPLETION(my_completion);ssize_tcompletion_read(structfile*filp,char__user*buf,size_tcount,loff_t*pos){printk(KERN_ALERT"%s,process%i(%s)goingtosleep",__FUNCTION__,current->pid,curre

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。