等待队列的使用

----------等待队列的使用----------
1.DEFINE_WAIT(wait);  //定义当前进程的等待队列wait

#define DEFINE_WAIT_FUNC(name, function)    \
wait_queue_t name = {      \
  .private = current,    \
  .func  = function,    \    //该函数被调用的情况:被__wake_up_common()调用
  .task_list = LIST_HEAD_INIT((name).task_list), \
 }
#defineDEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
typedef struct __wait_queue wait_queue_t;
struct__wait_queue{
 unsigned intflags; //唤醒方式
#define WQ_FLAG_EXCLUSIVE 0x01
 void *private;
 wait_queue_func_t func;
 struct list_head task_list;
};
//唤醒方式有 WQ_FLAG_EXCLUSIVE 或者 0;
WQ_FLAG_EXCLUSIVE:表示节点对应进程对临界资源使用具有排他性。在唤醒是会唤醒所有非排他性进程和一定数量的排他性进程。见__wake_up_common()函数:
static void __wake_up_common(wait_queue_head_t *q, unsigned int mode,
   int nr_exclusive, int wake_flags, void *key)
{
 wait_queue_t *curr, *next;
 list_for_each_entry_safe(curr, next, &q->task_list, task_list) {
  unsigned flags = curr->flags;
  if (curr->func(curr, mode, wake_flags, key) &&
    (flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
   break;
 }
}

2. prepare_to_wait(&pgdat->kswapd_wait, &wait,TASK_INTERRUPTIBLE);  //将wait挂在等待队列头kswapd_wait上

prepare_to_wait(wait_queue_head_t*q,wait_queue_t*wait, int state)
struct __wait_queue_head {
 spinlock_t lock;
 struct list_headtask_list;
};
typedef struct __wait_queue_head wait_queue_head_t;

3. schedule_timeout(HZ/10); //调度其他进程
4.finish_wait(&pgdat->kswapd_wait, &wait);  //当前进程被调度后,将wait从等待队列上删除


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值