code:setrun - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki

Source

  • 设置进程为就绪态
  • 如有需要的话将进程调入内存
  • 传入一个参数p

2129

2130 /*

2131  * Set the process running;

2132  * arrange for it to be swapped in if necessary.

2133  */

2134 setrun(p)

2135 {

2136     register struct proc *rp;

2137

2138     rp = p;

2139     rp->p_wchan = 0;

2140     rp->p_stat = SRUN;

  • 将睡眠原因置为0
  • 将进程状态置为SRUN(就绪状态)
2141     if(rp->p_pri < curpri)

2142           runrun++;

  • 若进程优先级比当前进程要高,则置runrun标志,以等待进程调度
2143     if(runout != 0 && (rp->p_flag&SLOAD) == 0) {

2144           runout = 0;

2145           wakeup(&runout);

  • 若runout已被置,且当前进程图象不在内存中
    • 则清runout标志,并唤醒因runout睡眠的0#进程,以调用sched函数将进程图象调入内存
  • 关于为何唤醒的是0#进程,参看进程调度之0#进程
2146     }

2147 }

2148 /* ------------------------- */

2149

Ref

Caller

⚠️ **GitHub.com Fallback** ⚠️