* Change thread state to be runnable, placing it on the run queue if * it is in memory. If it is swapped out, return true so our caller * will know to awaken the swapper. * * Requires the thread lock on entry, drops on exit. */
| 561 | * Requires the thread lock on entry, drops on exit. |
| 562 | */ |
| 563 | int |
| 564 | setrunnable(struct thread *td, int srqflags) |
| 565 | { |
| 566 | int swapin; |
| 567 | |
| 568 | THREAD_LOCK_ASSERT(td, MA_OWNED); |
| 569 | KASSERT(td->td_proc->p_state != PRS_ZOMBIE, |
| 570 | ("setrunnable: pid %d is a zombie", td->td_proc->p_pid)); |
| 571 | |
| 572 | swapin = 0; |
| 573 | switch (td->td_state) { |
| 574 | case TDS_RUNNING: |
| 575 | case TDS_RUNQ: |
| 576 | break; |
| 577 | case TDS_CAN_RUN: |
| 578 | KASSERT((td->td_flags & TDF_INMEM) != 0, |
| 579 | ("setrunnable: td %p not in mem, flags 0x%X inhibit 0x%X", |
| 580 | td, td->td_flags, td->td_inhibitors)); |
| 581 | /* unlocks thread lock according to flags */ |
| 582 | sched_wakeup(td, srqflags); |
| 583 | return (0); |
| 584 | case TDS_INHIBITED: |
| 585 | /* |
| 586 | * If we are only inhibited because we are swapped out |
| 587 | * arrange to swap in this process. |
| 588 | */ |
| 589 | if (td->td_inhibitors == TDI_SWAPPED && |
| 590 | (td->td_flags & TDF_SWAPINREQ) == 0) { |
| 591 | td->td_flags |= TDF_SWAPINREQ; |
| 592 | swapin = 1; |
| 593 | } |
| 594 | break; |
| 595 | default: |
| 596 | panic("setrunnable: state 0x%x", td->td_state); |
| 597 | } |
| 598 | if ((srqflags & (SRQ_HOLD | SRQ_HOLDTD)) == 0) |
| 599 | thread_unlock(td); |
| 600 | |
| 601 | return (swapin); |
| 602 | } |
| 603 | |
| 604 | /* |
| 605 | * Compute a tenex style load average of a quantity on |
no test coverage detected