diff options
author | jb <jb@FreeBSD.org> | 1998-11-15 09:58:26 +0000 |
---|---|---|
committer | jb <jb@FreeBSD.org> | 1998-11-15 09:58:26 +0000 |
commit | 3715314d366a89dbd7df6124d745c95e1bdde448 (patch) | |
tree | 9a0fe180209378fbce78fde57445392dcdc88fc5 /lib/libc_r | |
parent | ffd97e5342d926be2f35b764575b61c28801658c (diff) | |
download | FreeBSD-src-3715314d366a89dbd7df6124d745c95e1bdde448.zip FreeBSD-src-3715314d366a89dbd7df6124d745c95e1bdde448.tar.gz |
Close a window between unlocking a spinlock and changing the thread state.
Diffstat (limited to 'lib/libc_r')
-rw-r--r-- | lib/libc_r/uthread/pthread_private.h | 2 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_cond.c | 14 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_kern.c | 18 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_mutex.c | 18 |
4 files changed, 31 insertions, 21 deletions
diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h index 04600cf..e73f4f1 100644 --- a/lib/libc_r/uthread/pthread_private.h +++ b/lib/libc_r/uthread/pthread_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); diff --git a/lib/libc_r/uthread/uthread_cond.c b/lib/libc_r/uthread/uthread_cond.c index e9b687d..a085ea6 100644 --- a/lib/libc_r/uthread/uthread_cond.c +++ b/lib/libc_r/uthread/uthread_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/libc_r/uthread/uthread_kern.c b/lib/libc_r/uthread/uthread_kern.c index 22746c7..3a6966b 100644 --- a/lib/libc_r/uthread/uthread_kern.c +++ b/lib/libc_r/uthread/uthread_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 <errno.h> @@ -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/libc_r/uthread/uthread_mutex.c b/lib/libc_r/uthread/uthread_mutex.c index 4f4aa8a..a7e8dfe 100644 --- a/lib/libc_r/uthread/uthread_mutex.c +++ b/lib/libc_r/uthread/uthread_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); |