Reduce lock accesses in thread lock similarly to r311172.

This commit is contained in:
Mateusz Guzik 2017-01-03 23:08:11 +00:00
parent 30dcd18b90
commit 5e5ad162ad

View File

@ -754,7 +754,7 @@ void
thread_lock_flags_(struct thread *td, int opts, const char *file, int line)
{
struct mtx *m;
uintptr_t tid;
uintptr_t tid, v;
struct lock_delay_arg lda;
#ifdef LOCK_PROFILING
int contested = 0;
@ -796,10 +796,15 @@ thread_lock_flags_(struct thread *td, int opts, const char *file, int line)
m->lock_object.lo_name, file, line));
WITNESS_CHECKORDER(&m->lock_object,
opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line, NULL);
v = MTX_READ_VALUE(m);
for (;;) {
if (m->mtx_lock == MTX_UNOWNED && _mtx_obtain_lock(m, tid))
break;
if (m->mtx_lock == tid) {
if (v == MTX_UNOWNED) {
if (_mtx_obtain_lock(m, tid))
break;
v = MTX_READ_VALUE(m);
continue;
}
if (v == tid) {
m->mtx_recurse++;
break;
}
@ -810,7 +815,7 @@ thread_lock_flags_(struct thread *td, int opts, const char *file, int line)
&contested, &waittime);
/* Give interrupts a chance while we spin. */
spinlock_exit();
while (m->mtx_lock != MTX_UNOWNED) {
do {
if (lda.spin_cnt < 10000000) {
lock_delay(&lda);
} else {
@ -824,7 +829,8 @@ thread_lock_flags_(struct thread *td, int opts, const char *file, int line)
}
if (m != td->td_lock)
goto retry;
}
v = MTX_READ_VALUE(m);
} while (v != MTX_UNOWNED);
spinlock_enter();
}
if (m == td->td_lock)