diff options
author | jasone <jasone@FreeBSD.org> | 2000-06-14 17:17:41 +0000 |
---|---|---|
committer | jasone <jasone@FreeBSD.org> | 2000-06-14 17:17:41 +0000 |
commit | 9f479e9f39861a77981b3e6234e796caa25cfe0f (patch) | |
tree | 25b4c819ee7794359e6c426e91cd15c2c56a2f49 /lib/libc_r/uthread/uthread_mutex.c | |
parent | cc22f14b179a55f7686e798febd938bfef76c982 (diff) | |
download | FreeBSD-src-9f479e9f39861a77981b3e6234e796caa25cfe0f.zip FreeBSD-src-9f479e9f39861a77981b3e6234e796caa25cfe0f.tar.gz |
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
Diffstat (limited to 'lib/libc_r/uthread/uthread_mutex.c')
-rw-r--r-- | lib/libc_r/uthread/uthread_mutex.c | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/lib/libc_r/uthread/uthread_mutex.c b/lib/libc_r/uthread/uthread_mutex.c index c97c86b..12fdc8e 100644 --- a/lib/libc_r/uthread/uthread_mutex.c +++ b/lib/libc_r/uthread/uthread_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; |