MCPcopy Create free account
hub / github.com/F-Stack/f-stack / msleep_spin_sbt

Function msleep_spin_sbt

freebsd/kern/kern_synch.c:236–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236int
237msleep_spin_sbt(const void *ident, struct mtx *mtx, const char *wmesg,
238 sbintime_t sbt, sbintime_t pr, int flags)
239{
240 struct thread *td;
241 int rval;
242 WITNESS_SAVE_DECL(mtx);
243
244 td = curthread;
245 KASSERT(mtx != NULL, ("sleeping without a mutex"));
246 KASSERT(ident != NULL, ("msleep_spin_sbt: NULL ident"));
247 KASSERT(TD_IS_RUNNING(td), ("msleep_spin_sbt: curthread not running"));
248
249 if (SCHEDULER_STOPPED_TD(td))
250 return (0);
251
252 sleepq_lock(ident);
253 CTR5(KTR_PROC, "msleep_spin: thread %ld (pid %ld, %s) on %s (%p)",
254 td->td_tid, td->td_proc->p_pid, td->td_name, wmesg, ident);
255
256 DROP_GIANT();
257 mtx_assert(mtx, MA_OWNED | MA_NOTRECURSED);
258 WITNESS_SAVE(&mtx->lock_object, mtx);
259 mtx_unlock_spin(mtx);
260
261 /*
262 * We put ourselves on the sleep queue and start our timeout.
263 */
264 sleepq_add(ident, &mtx->lock_object, wmesg, SLEEPQ_SLEEP, 0);
265 if (sbt != 0)
266 sleepq_set_timeout_sbt(ident, sbt, pr, flags);
267
268 /*
269 * Can't call ktrace with any spin locks held so it can lock the
270 * ktrace_mtx lock, and WITNESS_WARN considers it an error to hold
271 * any spin lock. Thus, we have to drop the sleepq spin lock while
272 * we handle those requests. This is safe since we have placed our
273 * thread on the sleep queue already.
274 */
275#ifdef KTRACE
276 if (KTRPOINT(td, KTR_CSW)) {
277 sleepq_release(ident);
278 ktrcsw(1, 0, wmesg);
279 sleepq_lock(ident);
280 }
281#endif
282#ifdef WITNESS
283 sleepq_release(ident);
284 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "Sleeping on \"%s\"",
285 wmesg);
286 sleepq_lock(ident);
287#endif
288 if (sbt != 0)
289 rval = sleepq_timedwait(ident, 0);
290 else {
291 sleepq_wait(ident, 0);
292 rval = 0;
293 }

Callers

nothing calls this directly

Calls 8

sleepq_lockFunction · 0.85
mtx_assertFunction · 0.85
sleepq_addFunction · 0.85
sleepq_set_timeout_sbtFunction · 0.85
sleepq_releaseFunction · 0.85
ktrcswFunction · 0.85
sleepq_timedwaitFunction · 0.85
sleepq_waitFunction · 0.85

Tested by

no test coverage detected