#define wake_up_interruptible(x) __wake_up(x, TASK_INTERRUPTIBLE, 1, NULL)
void fastcall __wake_up(wait_queue_head_t *q,
unsigned int mode,
int nr_exclusive,
void *key)
{
unsigned long flags;
spin_lock_irqsave(&am
阻塞是指在执行设备操作的同时,若不能获得资源,则进程挂起直到满足可操作的条件在进行操作。
非阻塞操作是在进程不能执行设备操作时并不挂起。被挂起的程序进入休眠状态,一直等待条件满足
后才被执行,非阻塞模式则不会进入休眠状态,具体处理方式根据编程者的编程意图,所以一般情况
下,非阻塞的逻辑要比阻塞的逻辑复杂些,但是效率较高。
在linux驱动程序中,我们长使用等待队列来实现阻塞操作。wait queue
接着我们来说说,这次实验中要用到的两个函数
wait_event_interruptible();
wait_event_interruptible()。该函数修改task的状态为TASK_INTERRUPTIBLE,意味着该进程将不会继续运行直到被唤醒,然后被添加到等待队列中。
在wait_event_interruptible()中首先判断condition是不是已经满足,如果是则直接返回0,否则调用__wait_event_interruptible(),并用__ret来存放返回值
---------------------------------------------------------------
#define wait_event_interruptible(wq, condition) \
({ \
int __ret = 0; \
if (!(condition)) \
__wait_event_interruptible(wq, condition, __ret);\
__ret; \
})
wake_up_interruptible();
wake_up_interruptible负责唤醒状态为TASK_INTERRUPTIBLE的进程。