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
    评论
Linux内核中等待队列的函数原型主要包括以下几个: 1. wait_queue_head_t 类型 等待队列头结构体,用于表示等待队列。定义如下: ``` typedef struct { spinlock_t lock; struct list_head task_list; } wait_queue_head_t; ``` 2. wait_queue_entry_t 类型 等待队列项结构体,用于表示等待队列中的一个等待项。定义如下: ``` typedef struct { struct list_head entry; struct task_struct *task; unsigned int flags; void *private; } wait_queue_entry_t; ``` 3. init_waitqueue_head() 函数 用于初始化等待队列头,定义如下: ``` void init_waitqueue_head(wait_queue_head_t *q); ``` 4. prepare_to_wait() 函数 用于准备一个等待项,将其加入等待队列,并且将当前进程置为睡眠状态。定义如下: ``` void prepare_to_wait(wait_queue_head_t *q, wait_queue_entry_t *wait, int state); ``` 5. finish_wait() 函数 用于结束一个等待项,将其从等待队列中移除,并且将当前进程从睡眠状态唤醒。定义如下: ``` void finish_wait(wait_queue_head_t *q, wait_queue_entry_t *wait); ``` 6. wait_event() 函数 用于等待某个条件成立,如果条件不成立则将当前进程添加到等待队列中。定义如下: ``` unsigned long wait_event(wait_queue_head_t *q, unsigned long condition); ``` 7. wait_event_interruptible() 函数 与 wait_event() 函数类似,但是可以被中断。定义如下: ``` unsigned long wait_event_interruptible(wait_queue_head_t *q, unsigned long condition); ``` 8. wake_up() 函数 用于唤醒等待队列中的所有进程。定义如下: ``` void wake_up(wait_queue_head_t *q); ``` 9. wake_up_interruptible() 函数 与 wake_up() 函数类似,但是只唤醒可中断的等待项。定义如下: ``` void wake_up_interruptible(wait_queue_head_t *q); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值