From 7141f2ad460279c61b174777cf865e28a2e8574a Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Tue, 17 Apr 2001 03:34:52 +0000 Subject: [PATCH] Exit and re-enter the critical section while spinning for a spinlock so that interrupts can come in while we are waiting for a lock. --- sys/kern/kern_mutex.c | 3 +++ sys/kern/subr_turnstile.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 379b357370ff..6db0e8db1763 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -431,6 +431,8 @@ _mtx_lock_spin(struct mtx *m, int opts, critical_t mtx_crit, const char *file, if (_obtain_lock(m, curproc)) break; + /* Give interrupts a chance while we spin. */ + critical_exit(mtx_crit); while (m->mtx_lock != MTX_UNOWNED) { if (i++ < 1000000) continue; @@ -444,6 +446,7 @@ _mtx_lock_spin(struct mtx *m, int opts, critical_t mtx_crit, const char *file, panic("spin lock %s held by %p for > 5 seconds", m->mtx_object.lo_name, (void *)m->mtx_lock); } + mtx_crit = critical_enter(); } m->mtx_savecrit = mtx_crit; diff --git a/sys/kern/subr_turnstile.c b/sys/kern/subr_turnstile.c index 379b357370ff..6db0e8db1763 100644 --- a/sys/kern/subr_turnstile.c +++ b/sys/kern/subr_turnstile.c @@ -431,6 +431,8 @@ _mtx_lock_spin(struct mtx *m, int opts, critical_t mtx_crit, const char *file, if (_obtain_lock(m, curproc)) break; + /* Give interrupts a chance while we spin. */ + critical_exit(mtx_crit); while (m->mtx_lock != MTX_UNOWNED) { if (i++ < 1000000) continue; @@ -444,6 +446,7 @@ _mtx_lock_spin(struct mtx *m, int opts, critical_t mtx_crit, const char *file, panic("spin lock %s held by %p for > 5 seconds", m->mtx_object.lo_name, (void *)m->mtx_lock); } + mtx_crit = critical_enter(); } m->mtx_savecrit = mtx_crit;