From 408adb728768f69cb8966c1191020d6ea7e66be5 Mon Sep 17 00:00:00 2001 From: jhb Date: Tue, 4 Jun 2002 21:53:48 +0000 Subject: Optimize the adaptive mutex spin a bit. Use a simple while loop with simple reads (and on IA32, a "pause" instruction for each interation of the loop) to spin until either the mutex owner field changes, or the lock owner stops executing. Suggested by: tanimura Tested on: i386 --- sys/kern/kern_mutex.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sys/kern/kern_mutex.c') diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index f9b7413..d0fc8c9 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -536,9 +536,12 @@ _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line) owner = (struct thread *)(v & MTX_FLAGMASK); if (m != &Giant && thread_runnable(owner)) { mtx_unlock_spin(&sched_lock); + while (mtx_owner(m) == owner && + thread_runnable(owner)) { #ifdef __i386__ - ia32_pause(); + ia32_pause(); #endif + } continue; } #endif /* SMP && ADAPTIVE_MUTEXES */ -- cgit v1.1