睡眠函数里 spin_lock_irqsave(&q->lock,flags); 先关了中断
然后就 schedule()了, schedule()里是打开所有中断
void interruptible_sleep_on(wait_queue_head_t *q)
{
unsigned long flags;
wait_queue_t wait;
init_waitqueue_entry(&wait, current);
current->state = TASK_INTERRUPTIBLE;
spin_lock_irqsave(&q->lock,flags);
__add_wait_queue(q, &wait);
spin_unlock(&q->lock);
schedule();
spin_lock_irq(&q->lock);
__remove_wait_queue(q, &wait);
CU上一个帖子:
凡是可能睡眠的函数都不能在中断环境中调用,那么这些函数是否可以在关中断的情况下调用呢?
在关中断的条件下,是可以睡眠的,但是这会导致系统状态不正确,因为在shedule函数中,会无条件地打开所有的中断,然后当我们再此运行的时候,虽然在我们代码中认为是关中断的状态,但其实中断已经被打开。
所以总的来说,在关中断的条件下也是不可以睡眠的,只是系统没有为这个条件引发一个BUG。
然后就 schedule()了, schedule()里是打开所有中断
void interruptible_sleep_on(wait_queue_head_t *q)
{
unsigned long flags;
wait_queue_t wait;
init_waitqueue_entry(&wait, current);
current->state = TASK_INTERRUPTIBLE;
spin_lock_irqsave(&q->lock,flags);
__add_wait_queue(q, &wait);
spin_unlock(&q->lock);
schedule();
spin_lock_irq(&q->lock);
__remove_wait_queue(q, &wait);
CU上一个帖子:
凡是可能睡眠的函数都不能在中断环境中调用,那么这些函数是否可以在关中断的情况下调用呢?
在关中断的条件下,是可以睡眠的,但是这会导致系统状态不正确,因为在shedule函数中,会无条件地打开所有的中断,然后当我们再此运行的时候,虽然在我们代码中认为是关中断的状态,但其实中断已经被打开。
所以总的来说,在关中断的条件下也是不可以睡眠的,只是系统没有为这个条件引发一个BUG。