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

Function _mtx_lock_spin_cookie

freebsd/kern/kern_mutex.c:703–797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

701 const char *file, int line)
702#else
703void
704_mtx_lock_spin_cookie(volatile uintptr_t *c, uintptr_t v)
705#endif
706{
707 struct mtx *m;
708 struct lock_delay_arg lda;
709 uintptr_t tid;
710#ifdef LOCK_PROFILING
711 int contested = 0;
712 uint64_t waittime = 0;
713#endif
714#ifdef KDTRACE_HOOKS
715 int64_t spin_time = 0;
716#endif
717#if defined(KDTRACE_HOOKS) || defined(LOCK_PROFILING)
718 int doing_lockprof = 0;
719#endif
720
721 tid = (uintptr_t)curthread;
722 m = mtxlock2mtx(c);
723
724#ifdef KDTRACE_HOOKS
725 if (LOCKSTAT_PROFILE_ENABLED(adaptive__acquire)) {
726 while (v == MTX_UNOWNED) {
727 if (_mtx_obtain_lock_fetch(m, &v, tid))
728 goto out_lockstat;
729 }
730 doing_lockprof = 1;
731 spin_time -= lockstat_nsecs(&m->lock_object);
732 }
733#endif
734#ifdef LOCK_PROFILING
735 doing_lockprof = 1;
736#endif
737
738 if (__predict_false(v == MTX_UNOWNED))
739 v = MTX_READ_VALUE(m);
740
741 if (__predict_false(v == tid)) {
742 m->mtx_recurse++;
743 return;
744 }
745
746 if (SCHEDULER_STOPPED())
747 return;
748
749 if (LOCK_LOG_TEST(&m->lock_object, opts))
750 CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m);
751 KTR_STATE1(KTR_SCHED, "thread", sched_tdname((struct thread *)tid),
752 "spinning", "lockname:\"%s\"", m->lock_object.lo_name);
753
754 lock_delay_arg_init(&lda, &mtx_spin_delay);
755
756#ifdef HWPMC_HOOKS
757 PMC_SOFT_CALL( , , lock, failed);
758#endif
759 lock_profile_obtain_lock_failed(&m->lock_object, &contested, &waittime);
760

Callers

nothing calls this directly

Calls 8

lockstat_nsecsFunction · 0.85
lock_delay_arg_initFunction · 0.85
lock_delayFunction · 0.85
sched_tdnameFunction · 0.70
spinlock_exitFunction · 0.50
spinlock_enterFunction · 0.50

Tested by

no test coverage detected