Linux中的工作队列(work queue)
工作队列(work queue)是Linux kernel中将工作推后执行的一种机制。这种机制和BH(bottom half)或Tasklets不同之处在于工作队列是把推后的工作交由一个内核线程去执行,因此工作队列的优势就在于它允许重新调度甚至睡眠。
linux 2.6.20以后,工作队列机制和之前的版本有一点不同,在网上找了一点资料,也相应的看了一些code,现在自己总结一下:
原文参考:
http://wiki.365linux.cn/index.php?doc-view-39
http://blog.csdn.net/lanmanck/archive/2009/11/05/4770030.aspx
work queue的头文件: /kernel/include/linux/workqueue.h
work queue的数据结构:
struct work_struct {
atomic_long_t data;
#define WORK_STRUCT_PENDING 0 /* T if work item pending execution */
#define WORK_STRUCT_FLAG_MASK (3UL)
#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
struct list_head entry;
work_func_t func;
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
};
其中 work_func_t 的定义如下:
typedef void (*work_func_t)(struct work_struct *work);
work queue 主要的 API:
INIT_WORK(struct work_struct *work, work_func_t func)
INIT_DELAYED_WORK(struct delayed_work *work, work_func_t func)
int schedule_work(struct work_struct *work)
void flush_scheduled_work(void)
int schedule_delayed_work(struct delayed_work *work, unsigned long delay)
int cancel_delayed_work(struct delayed_work *work)
struct workqueue_struct *create_workqueue(const char *name)
int queue_work(struct workqueue_struct *wq, struct work_struct *work)
int queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay)
void flush_workqueue(struct workqueue_struct *wq)
void destroy_workqueue(struct workqueue_struct *wq)
work queue 的使用实例:
struct my_work_t {
ch
相关文档:
例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......
在Windwos中,系统时间的设置很简单,界面操作,通俗易懂。而且设置后,重启,关机都没关系。系统时间会自动保存在Bios的时钟里面,启动计算机的时候,系统会自动在Bios里面取硬件时间,以保证时间的不间断。 但在Linux下,默认情况下,系统时间和硬件时间,并不会自动同步。在Linu ......
from: http://www.21andy.com/blog/20060820/389.html
linux解压 tar命令
tar命令
tar [-cxtzjvfpPN] 文件与目录 ....
参数:
-c :建立一个压缩文件的参数指令(create 的意思);
-x :解开一个压缩文件的参数指令!
-t :查看 tarfile 里面的文件!
特别注意,在参数的下达中, c/x/t 仅能存在一个!不 ......
Form: http://tech.sina.com.cn/c/4082.html
Linux中文件的压缩与解压缩
http://www.sina.com.cn 2001/06/28 14:15 赛迪网 李革新
对许多用户来说,在DOS和Windows环境下利用工具软件ARJ、Winzip等,压缩或解压文件是比较容易的事。但是,在Linux中如何对文件进行压缩与解压呢?本文基于Red Ha ......