linux查看等待队列,linux等待队列(Linux wait queue).doc

linux等待队列(Linux wait queue)

linux等待队列(Linux wait queue)

The waiting queue of Linux kernel is based on double loop linked list, and is closely integrated with the process scheduling mechanism. It can be used to realize the core asynchronous event notification mechanism. In this list, there are two data structures: the waiting queue header (wait_queue_head_t) and the waiting queue item wait_queue_t. The waiting queue headers and waiting queue entries contain a domain of type list_head as the connector". Because we only need to queue to add and delete operations, and will not modify the object, so we only need to provide a protection for the entire infrastructure and the lock on the object, the lock in the wait queue head, wq_lock_t.

Waiting queues in the kernel have many uses, especially in dealing with interrupts, processes, synchronization, timing, and so on. You can use the wait queue in the wake of the blocking process. It is a queue based data structure and closely integrated with the process scheduling mechanism. Can be used to implement asynchronous event notification mechanisms in the kernel. Synchronize access to system resources.

Commonly used structures:

Struct __wait_queue_head {

Spinlock_t lock;

Struct list_head task_list;

};

Typedef struct __wait_queue_head wait_queue_head_t;

Struct __wait_queue {

Unsigned int flags;

#define WQ_FLAG_EXCLUSIVE 0x01

Void *private;

Wait_queue_func_t func;

Struct list_head task_list;

};

Typedef struct __wait_queue wait_queue_t;

Field detail:

(1) spinlock_t lock;

In the operation of task_list, the mutex is used to achieve exclusive access to the waiting queue.

(2) struct, list_head, task_list;

Bidirectional circular list used to store waiting queues.

Common operations:

(1) define and initialize

Void init_waitqueue_head (wait_queue_head_t *q)

{

Spin_lock_init (&q->lock); / / initialize atomic operation

INIT_LIST_HEAD (&q->task_list); / / initialize list_head

}

Another method of using macros to initialize waiting queues:

D#define DECLARE_WAIT_QUEUE_HEAD (

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值