- 论坛徽章:
- 0
|
在kern/kern_switch.c的critical_exit()有这样一段代码:- if (td->td_critnest == 1) {
- td->td_critnest = 0;
- if (td->td_owepreempt && !kdb_active) {
- td->td_critnest = 1;
- thread_lock(td);
- td->td_critnest--;
- flags = SW_INVOL | SW_PREEMPT;
- if (TD_IS_IDLETHREAD(td))
- flags |= SWT_IDLE;
- else
- flags |= SWT_OWEPREEMPT;
- mi_switch(flags, NULL);
- thread_unlock(td);
- }
- } else
- td->td_critnest--;
复制代码 为什么不直接这样写呢?- if (td->td_critnest == 1) {
- if (td->td_owepreempt && !kdb_active) {
- thread_lock(td);
- td->td_critnest--;
- flags = SW_INVOL | SW_PREEMPT;
- if (TD_IS_IDLETHREAD(td))
- flags |= SWT_IDLE;
- else
- flags |= SWT_OWEPREEMPT;
- mi_switch(flags, NULL);
- thread_unlock(td);
- } else
- td->td_critnest = 0;
- } else
- td->td_critnest--;
复制代码 我不理解先把td->td_critnest设置为0,然后检测到td->td_owepreempt的时候,再把td->td_critnest设置为1,并锁上td再对它减一的用意。另外这样做是否会存在副作用呢?td_critnest = 1 应该是要关闭内核抢占,检测到td->td_owepreempt后把td_critnest设置为1,应该意味着需要这个条件下是需要关闭内核抢占的,那么前一句的td->td_critness = 0开启内核抢占会不会有副作用呢?
|
|