????B????:
????100 spin_lock(&list_lock);
????101 list_add_tail(&list_head?? new_node);
????102 spin_unlock(&list_lock);
????103 wake_up_process(processa_task);
??????????????????????統(tǒng)A??????е???3?к??4????????B????????????????????????????С?????????????B????????????????е????????????????A????????????A???????н???????????????????Ч?????????A ?????????У???????????????????????????????????????????????TASK_INTERRUPTIBLE??????schedule()????????????????B???????????????????????????????????Ч??????????????????????????????????A ???????????????
????3????????Ч????
??????α?????Ч????????????????????Ч???????????????????????????????????????????? ????B?????wake_up_process()??????ν?A?????????TASK_RUNNING ??????????????A????????????TASK_RUNNING??????wake_up_process()??A???????????????????????????? ????????????á????????????????????????????????ж????????????y?????????????????????????????У????????????????? ???????????????????????????wake_up_process ()????????????????????????????????
???????????????????????A???????????????????????????е???Ч???????????
????A????:
1 set_current_state(TASK_INTERRUPTIBLE);
2 spin_lock(&list_lock);
3 if(list_empty(&list_head)) {
4 spin_unlock(&list_lock);
5 schedule();
6 spin_lock(&list_lock);
7 }
8 set_current_state(TASK_RUNNING);
9
10 /* Rest of the code ... */
11 spin_unlock(&list_lock);
???????????????δ?????????????????????н?????????ó?TASK_INTERRUPTIBLE????????????????????????????????TASK_RUNNING??????????????B??????A????????????????????????wake_up_process()?????A?????????????????TASK_INTERRUPTIBLE???TASK_RUNNING?????????????????schedule()?????????????????TASK_RUNNING??????????????????ж????????????????????????????????????????Ч????????
????4??Linux????????
??????Linux???????У???????????????????????????Linux??????????г?????Ч????????Linux????????????????????????????????μ??????
????/* ‘q’??????????????????? */
????DECLARE_WAITQUEUE(wait??current);
????add_wait_queue(q?? &wait);
????set_current_state(TASK_INTERRUPTIBLE);
????/* ??TASK_INTERRUPTIBLE */
????while(!condition) /* ‘condition’ ??????????*/
????schedule();
????set_current_state(TASK_RUNNING);
????remove_wait_queue(q?? &wait);
????????????????y??????????????в??譎??????????????????????н??????????????DECLARE_WAITQUEUE ()?????????????е?????????add_wait_queue()?????????????????У?????????????????? TASK_INTERRUPTIBLE ????TASK_INTERRUPTIBLE????????????????????棺?????????б?????????????????棬????schedule()???????? ????????????????????????????TASK_RUNNING ??????remove_wait_queue()??????????????С?
??????????????????Linux????????????????????????????????y??????????????
???????????????????????????????????????????????????????????????set_current_state()???????????????????????????????????????????????????????????????3?????Ч????????
????????????????linux ????е??????????Linux ???????α?????Ч???????δ??????Linux2.6?????(linux-2.6.11/kernel/sched.c: 4254):
????4253 /* Wait for kthread_stop */
????4254 set_current_state(TASK_INTERRUPTIBLE);
????4255 while (!kthread_should_stop()) {
????4256 schedule();
????4257 set_current_state(TASK_INTERRUPTIBLE);
????4258 }
????4259 __set_current_state(TASK_RUNNING);
????4260 return 0;
???????????Щ?????????????????migration_thread??????????????kthread_should_stop()?????kthread_should_stop()????1?????????????????????kthread_should_stop()????0?y??????? ?????????????????????????kthread_should_stop()?????????????????TASK_INTERRUPTIBLE???????е?????????????????????????schedule()???????????????????????????y???????????????Ч??
????С??
??????????????????????????Linux ?б?????????Ч??????????????????????????????????TASK_INTERRUPTIBLE??TASK_UNINTERRUPTIBLE?????????????????????????y??????????????TASK_RUNNING???????????????????????????? ??????????????????????ж???????????????????????????Ч????????