From 11c30e289f54a168d95ce9734017853b21169f73 Mon Sep 17 00:00:00 2001 From: Marco S Hyman Date: Mon, 12 Nov 2001 02:24:31 +0000 Subject: This fixes the recursive mutex problem with pthreads. fgs@ says their is a better fix... if so he can back these changes out and apply his fix at his convenience. In the meanwhile we'll have mutexen that work. --- lib/libpthread/uthread/uthread_mutex.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/libpthread/uthread') diff --git a/lib/libpthread/uthread/uthread_mutex.c b/lib/libpthread/uthread/uthread_mutex.c index 782808b5831..4fc3962fa83 100644 --- a/lib/libpthread/uthread/uthread_mutex.c +++ b/lib/libpthread/uthread/uthread_mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_mutex.c,v 1.11 2000/01/06 07:19:35 d Exp $ */ +/* $OpenBSD: uthread_mutex.c,v 1.12 2001/11/12 02:24:30 marc Exp $ */ /* * Copyright (c) 1995 John Birrell . * All rights reserved. @@ -134,7 +134,7 @@ pthread_mutex_init(pthread_mutex_t * mutex, /* Check mutex protocol: */ else if (((*mutex_attr)->m_protocol < PTHREAD_PRIO_NONE) || - ((*mutex_attr)->m_protocol > PTHREAD_MUTEX_RECURSIVE)) + ((*mutex_attr)->m_protocol > PTHREAD_PRIO_PROTECT)) /* Return an invalid argument error: */ ret = EINVAL; @@ -438,6 +438,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex) /* Lock the mutex for this thread: */ (*mutex)->m_owner = _thread_run; + /* if recursive, increment the lock count */ + if ((*mutex)->m_type == PTHREAD_MUTEX_RECURSIVE) + (*mutex)->m_data.m_count++; + /* Add to the list of owned mutexes: */ _MUTEX_ASSERT_NOT_OWNED(*mutex); TAILQ_INSERT_TAIL(&_thread_run->mutexq, @@ -477,6 +481,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex) /* Lock the mutex for this thread: */ (*mutex)->m_owner = _thread_run; + /* if recursive, increment the lock count */ + if ((*mutex)->m_type == PTHREAD_MUTEX_RECURSIVE) + (*mutex)->m_data.m_count++; + /* Track number of priority mutexes owned: */ _thread_run->priority_mutex_count++; @@ -541,6 +549,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex) */ (*mutex)->m_owner = _thread_run; + /* if recursive, increment the lock count */ + if ((*mutex)->m_type == PTHREAD_MUTEX_RECURSIVE) + (*mutex)->m_data.m_count++; + /* Track number of priority mutexes owned: */ _thread_run->priority_mutex_count++; -- cgit v1.2.3