From 3715314d366a89dbd7df6124d745c95e1bdde448 Mon Sep 17 00:00:00 2001 From: jb Date: Sun, 15 Nov 1998 09:58:26 +0000 Subject: Close a window between unlocking a spinlock and changing the thread state. --- lib/libkse/thread/thr_cond.c | 14 ++++---------- lib/libkse/thread/thr_kern.c | 18 +++++++++++++++++- lib/libkse/thread/thr_mutex.c | 18 ++++++++---------- lib/libkse/thread/thr_private.h | 2 ++ 4 files changed, 31 insertions(+), 21 deletions(-) (limited to 'lib/libkse') diff --git a/lib/libkse/thread/thr_cond.c b/lib/libkse/thread/thr_cond.c index e9b687d..a085ea6 100644 --- a/lib/libkse/thread/thr_cond.c +++ b/lib/libkse/thread/thr_cond.c @@ -165,12 +165,9 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) /* Unlock the condition variable structure: */ _SPINUNLOCK(&(*cond)->lock); } else { - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - /* Schedule the next thread: */ - _thread_kern_sched_state(PS_COND_WAIT, - __FILE__, __LINE__); + _thread_kern_sched_state_unlock(PS_COND_WAIT, + &(*cond)->lock, __FILE__, __LINE__); /* Lock the mutex: */ rval = pthread_mutex_lock(mutex); @@ -241,12 +238,9 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, /* Unlock the condition variable structure: */ _SPINUNLOCK(&(*cond)->lock); } else { - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - /* Schedule the next thread: */ - _thread_kern_sched_state(PS_COND_WAIT, - __FILE__, __LINE__); + _thread_kern_sched_state_unlock(PS_COND_WAIT, + &(*cond)->lock, __FILE__, __LINE__); /* Lock the mutex: */ if ((rval = pthread_mutex_lock(mutex)) != 0) { diff --git a/lib/libkse/thread/thr_kern.c b/lib/libkse/thread/thr_kern.c index 22746c7..3a6966b 100644 --- a/lib/libkse/thread/thr_kern.c +++ b/lib/libkse/thread/thr_kern.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_kern.c,v 1.13 1998/09/30 06:36:56 jb Exp $ + * $Id: uthread_kern.c,v 1.14 1998/10/09 19:01:30 dt Exp $ * */ #include @@ -616,6 +616,22 @@ _thread_kern_sched_state(enum pthread_state state, char *fname, int lineno) return; } +void +_thread_kern_sched_state_unlock(enum pthread_state state, + spinlock_t *lock, char *fname, int lineno) +{ + /* Change the state of the current thread: */ + _thread_run->state = state; + _thread_run->fname = fname; + _thread_run->lineno = lineno; + + _SPINUNLOCK(lock); + + /* Schedule the next thread that is ready: */ + _thread_kern_sched(NULL); + return; +} + static void _thread_kern_select(int wait_reqd) { diff --git a/lib/libkse/thread/thr_mutex.c b/lib/libkse/thread/thr_mutex.c index 4f4aa8a..a7e8dfe 100644 --- a/lib/libkse/thread/thr_mutex.c +++ b/lib/libkse/thread/thr_mutex.c @@ -257,11 +257,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex) */ _thread_queue_enq(&(*mutex)->m_queue, _thread_run); - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - - /* Block signals: */ - _thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__); + /* Wait for the mutex: */ + _thread_kern_sched_state_unlock( + PS_MUTEX_WAIT, &(*mutex)->lock, + __FILE__, __LINE__); /* Lock the mutex again: */ _SPINLOCK(&(*mutex)->lock); @@ -290,11 +289,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex) */ _thread_queue_enq(&(*mutex)->m_queue, _thread_run); - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - - /* Block signals: */ - _thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__); + /* Wait for the mutex: */ + _thread_kern_sched_state_unlock( + PS_MUTEX_WAIT, &(*mutex)->lock, + __FILE__, __LINE__); /* Lock the mutex again: */ _SPINLOCK(&(*mutex)->lock); diff --git a/lib/libkse/thread/thr_private.h b/lib/libkse/thread/thr_private.h index 04600cf..e73f4f1 100644 --- a/lib/libkse/thread/thr_private.h +++ b/lib/libkse/thread/thr_private.h @@ -654,6 +654,8 @@ void _thread_dump_info(void); void _thread_init(void); void _thread_kern_sched(struct sigcontext *); void _thread_kern_sched_state(enum pthread_state,char *fname,int lineno); +void _thread_kern_sched_state_unlock(enum pthread_state state, + spinlock_t *lock, char *fname, int lineno); void _thread_kern_set_timeout(struct timespec *); void _thread_sig_handler(int, int, struct sigcontext *); void _thread_start(void); -- cgit v1.1