new linux device driver - wait queue
github-wait queue example
1. INIT_WORK
產生一個 function work
static struct work_struct wrk;
static void work_handler(struct work_struct *work)
{
...
}
INIT_WORK(&wrk, work_handler);
2. schedule_work
將 work 放到 working queue 中
schedule_work(&wrk);
3. wake_up_interruptible / wait_event_interruptible
wake_up_interruptible(&mwq);
wait_event_interruptible(mwq, wake_up);
wake_up_interruptible 只是將相對應的 work thread, 從 waiting queue 搬到 working queue,
因此下一行 顯示 after send wake_up, 大多會先出來. ( 和 scheduling 機制有關 )
wait_event_interruptible 第二個參數為 boolean , true 時才會跳出等待繼續執行
程式:
結果:
hello_init: Start to wait
work_handler start sleep 3 sec.
work_handler before send wake_up
work_handler after send wake_up
hello_init: wakeup
.
1. INIT_WORK
產生一個 function work
static struct work_struct wrk;
static void work_handler(struct work_struct *work)
{
...
}
INIT_WORK(&wrk, work_handler);
2. schedule_work
將 work 放到 working queue 中
schedule_work(&wrk);
wake_up_interruptible(&mwq);
wait_event_interruptible(mwq, wake_up);
wake_up_interruptible 只是將相對應的 work thread, 從 waiting queue 搬到 working queue,
因此下一行 顯示 after send wake_up, 大多會先出來. ( 和 scheduling 機制有關 )
wait_event_interruptible 第二個參數為 boolean , true 時才會跳出等待繼續執行
程式:
結果:
hello_init: Start to wait
work_handler start sleep 3 sec.
work_handler before send wake_up
work_handler after send wake_up
hello_init: wakeup
.
留言
張貼留言