Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_synch.c
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
int | int | ||||
_sleep(const void *ident, struct lock_object *lock, int priority, | _sleep(const void *ident, struct lock_object *lock, int priority, | ||||
const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags) | const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags) | ||||
{ | { | ||||
struct thread *td; | struct thread *td; | ||||
struct lock_class *class; | struct lock_class *class; | ||||
uintptr_t lock_state; | uintptr_t lock_state; | ||||
int catch, pri, rval, sleepq_flags; | int catch, userw, pri, rval, sleepq_flags; | ||||
WITNESS_SAVE_DECL(lock_witness); | WITNESS_SAVE_DECL(lock_witness); | ||||
td = curthread; | td = curthread; | ||||
#ifdef KTRACE | #ifdef KTRACE | ||||
if (KTRPOINT(td, KTR_CSW)) | if (KTRPOINT(td, KTR_CSW)) | ||||
ktrcsw(1, 0, wmesg); | ktrcsw(1, 0, wmesg); | ||||
#endif | #endif | ||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock, | WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock, | ||||
Show All 11 Lines | else | ||||
class = NULL; | class = NULL; | ||||
if (SCHEDULER_STOPPED_TD(td)) { | if (SCHEDULER_STOPPED_TD(td)) { | ||||
if (lock != NULL && priority & PDROP) | if (lock != NULL && priority & PDROP) | ||||
class->lc_unlock(lock); | class->lc_unlock(lock); | ||||
return (0); | return (0); | ||||
} | } | ||||
catch = priority & PCATCH; | catch = priority & PCATCH; | ||||
userw = priority & PUSERW; | |||||
pri = priority & PRIMASK; | pri = priority & PRIMASK; | ||||
KASSERT(!TD_ON_SLEEPQ(td), ("recursive sleep")); | KASSERT(!TD_ON_SLEEPQ(td), ("recursive sleep")); | ||||
if ((uintptr_t)ident >= (uintptr_t)&pause_wchan[0] && | if ((uintptr_t)ident >= (uintptr_t)&pause_wchan[0] && | ||||
(uintptr_t)ident <= (uintptr_t)&pause_wchan[MAXCPU - 1]) | (uintptr_t)ident <= (uintptr_t)&pause_wchan[MAXCPU - 1]) | ||||
sleepq_flags = SLEEPQ_PAUSE; | sleepq_flags = SLEEPQ_PAUSE; | ||||
else | else | ||||
sleepq_flags = SLEEPQ_SLEEP; | sleepq_flags = SLEEPQ_SLEEP; | ||||
if (catch) | if (catch) | ||||
sleepq_flags |= SLEEPQ_INTERRUPTIBLE; | sleepq_flags |= SLEEPQ_INTERRUPTIBLE; | ||||
if (userw) | |||||
sleepq_flags |= SLEEPQ_USERWAIT; | |||||
sleepq_lock(ident); | sleepq_lock(ident); | ||||
CTR5(KTR_PROC, "sleep: thread %ld (pid %ld, %s) on %s (%p)", | CTR5(KTR_PROC, "sleep: thread %ld (pid %ld, %s) on %s (%p)", | ||||
td->td_tid, td->td_proc->p_pid, td->td_name, wmesg, ident); | td->td_tid, td->td_proc->p_pid, td->td_name, wmesg, ident); | ||||
if (lock == &Giant.lock_object) | if (lock == &Giant.lock_object) | ||||
mtx_assert(&Giant, MA_OWNED); | mtx_assert(&Giant, MA_OWNED); | ||||
DROP_GIANT(); | DROP_GIANT(); | ||||
▲ Show 20 Lines • Show All 498 Lines • Show Last 20 Lines |