1.struct work_struct
struct work_struct是 Linux 内核中用于表示工作项(work item)的结构体,在 Linux 内核中,工作项是一项需要被异步执行的任务。通过创建一个 struct work_struct 对象,并将其添加到工作队列中,可以使得内核在适当的时机执行该工作项的回调函数。
struct work_struct {
atomic_long_t data;
struct list_head entry;
work_func_t func;
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
};
- data:工作项的数据,可用于传递参数或状态信息给工作项回调函数。
- entry:工作项在工作队列中的链表入口,用于将工作项链接到适当的工作队列中。
- func:指向工作项回调函数的指针,当工作项被执行时,将调用该回调函数
2.struct workqueue_struct
struct workqueue_struct` 是 Linux 内核中表示工作队列的结构体。工作队列是一种用于异步执行延迟任务的机制,可以在后台线程中执行工作项。struct workqueue_struct用于表示一个工