* Used by the thread to poll as to whether it should yield/sleep * and notify the caller that is has happened. */
| 431 | * and notify the caller that is has happened. |
| 432 | */ |
| 433 | void |
| 434 | kthread_suspend_check(void) |
| 435 | { |
| 436 | struct proc *p; |
| 437 | struct thread *td; |
| 438 | |
| 439 | td = curthread; |
| 440 | p = td->td_proc; |
| 441 | |
| 442 | if ((td->td_pflags & TDP_KTHREAD) == 0) |
| 443 | panic("%s: curthread is not a valid kthread", __func__); |
| 444 | |
| 445 | /* |
| 446 | * Setting the TDF_KTH_SUSP flag is protected by process lock. |
| 447 | * |
| 448 | * Do an unlocked read first to avoid serializing with all other threads |
| 449 | * in the common case of not suspending. |
| 450 | */ |
| 451 | if ((td->td_flags & TDF_KTH_SUSP) == 0) |
| 452 | return; |
| 453 | PROC_LOCK(p); |
| 454 | while ((td->td_flags & TDF_KTH_SUSP) != 0) { |
| 455 | wakeup(&td->td_flags); |
| 456 | msleep(&td->td_flags, &p->p_mtx, PPAUSE, "ktsusp", 0); |
| 457 | } |
| 458 | PROC_UNLOCK(p); |
| 459 | } |
| 460 | |
| 461 | int |
| 462 | kproc_kthread_add(void (*func)(void *), void *arg, |
no test coverage detected