From 9f479e9f39861a77981b3e6234e796caa25cfe0f Mon Sep 17 00:00:00 2001 From: jasone Date: Wed, 14 Jun 2000 17:17:41 +0000 Subject: pthread_mutex_lock(), pthread_cond_trywait(), and pthread_cond_wait() are not allowed to return EINTR, but use of pthread_suspend_np() could cause EINTR to be returned. To fix this, restructure pthread_suspend_np() so that it does not interrupt a thread that is waiting on a mutex or condition, and keep enough state around that pthread_resume_np() can fix things up afterwards. Reviewed by: deischen --- lib/libkse/thread/thr_mutex.c | 52 ++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 13 deletions(-) (limited to 'lib/libkse/thread/thr_mutex.c') diff --git a/lib/libkse/thread/thr_mutex.c b/lib/libkse/thread/thr_mutex.c index c97c86b..12fdc8e 100644 --- a/lib/libkse/thread/thr_mutex.c +++ b/lib/libkse/thread/thr_mutex.c @@ -612,7 +612,6 @@ pthread_mutex_lock(pthread_mutex_t * mutex) */ if (_thread_run->interrupted != 0) { mutex_queue_remove(*mutex, _thread_run); - ret = EINTR; } /* Unlock the mutex structure: */ @@ -777,11 +776,20 @@ mutex_unlock_common(pthread_mutex_t * mutex, int add_reference) if (((*mutex)->m_owner = mutex_queue_deq(*mutex)) != NULL) { /* - * Allow the new owner of the mutex to - * run: + * Unless the new owner of the mutex is + * currently suspended, allow the owner + * to run. If the thread is suspended, + * make a note that the thread isn't in + * a wait queue any more. */ - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); + if (((*mutex)->m_owner->state != + PS_SUSPENDED)) { + PTHREAD_NEW_STATE((*mutex)->m_owner, + PS_RUNNING); + } else { + (*mutex)->m_owner->suspended = + SUSP_NOWAIT; + } /* * Add the mutex to the threads list of @@ -899,11 +907,20 @@ mutex_unlock_common(pthread_mutex_t * mutex, int add_reference) (*mutex)->m_prio; /* - * Allow the new owner of the mutex to - * run: + * Unless the new owner of the mutex is + * currently suspended, allow the owner + * to run. If the thread is suspended, + * make a note that the thread isn't in + * a wait queue any more. */ - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); + if (((*mutex)->m_owner->state != + PS_SUSPENDED)) { + PTHREAD_NEW_STATE((*mutex)->m_owner, + PS_RUNNING); + } else { + (*mutex)->m_owner->suspended = + SUSP_NOWAIT; + } } } break; @@ -1019,11 +1036,20 @@ mutex_unlock_common(pthread_mutex_t * mutex, int add_reference) (*mutex)->m_prio; /* - * Allow the new owner of the mutex to - * run: + * Unless the new owner of the mutex is + * currently suspended, allow the owner + * to run. If the thread is suspended, + * make a note that the thread isn't in + * a wait queue any more. */ - PTHREAD_NEW_STATE((*mutex)->m_owner, - PS_RUNNING); + if (((*mutex)->m_owner->state != + PS_SUSPENDED)) { + PTHREAD_NEW_STATE((*mutex)->m_owner, + PS_RUNNING); + } else { + (*mutex)->m_owner->suspended = + SUSP_NOWAIT; + } } } break; -- cgit v1.1