diff options
-rw-r--r-- | lib/libthr/thread/thr_mutex.c | 2 | ||||
-rw-r--r-- | lib/libthr/thread/thr_rwlock.c | 36 | ||||
-rw-r--r-- | lib/libthr/thread/thr_setschedparam.c | 1 |
3 files changed, 19 insertions, 20 deletions
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index ca16cb6..2771a65 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -840,6 +840,8 @@ void readjust_priorities(struct pthread *pthread, struct pthread_mutex *mtx) { if ((pthread->flags & PTHREAD_FLAGS_IN_MUTEXQ) != 0) { + PTHREAD_ASSERT(mtx != NULL, + "mutex is NULL when it should not be"); mutex_queue_remove(mtx, pthread); mutex_queue_enq(mtx, pthread); PTHREAD_LOCK(mtx->m_owner); diff --git a/lib/libthr/thread/thr_rwlock.c b/lib/libthr/thread/thr_rwlock.c index a988d4a..73c489e 100644 --- a/lib/libthr/thread/thr_rwlock.c +++ b/lib/libthr/thread/thr_rwlock.c @@ -264,19 +264,15 @@ _pthread_rwlock_unlock (pthread_rwlock_t *rwlock) goto out; } if (prwlock->state > 0) { + PTHREAD_ASSERT(rh->rh_wrcount == 0, + "write count on a readlock should be zero!"); rh->rh_rdcount--; - if (rh->rh_rdcount == 0) { - LIST_REMOVE(rh, rh_link); - free(rh); - } if (--prwlock->state == 0 && prwlock->blocked_writers) ret = pthread_cond_signal(&prwlock->write_signal); } else if (prwlock->state < 0) { + PTHREAD_ASSERT(rh->rh_rdcount == 0, + "read count on a writelock should be zero!"); rh->rh_wrcount--; - if (rh->rh_wrcount == 0) { - LIST_REMOVE(rh, rh_link); - free(rh); - } prwlock->state = 0; if (prwlock->blocked_writers) ret = pthread_cond_signal(&prwlock->write_signal); @@ -290,6 +286,10 @@ _pthread_rwlock_unlock (pthread_rwlock_t *rwlock) ret = EPERM; goto out; } + if (rh->rh_wrcount == 0 && rh->rh_rdcount == 0) { + LIST_REMOVE(rh, rh_link); + free(rh); + } out: /* see the comment on this in rwlock_rdlock_common */ @@ -360,8 +360,10 @@ rwlock_wrlock_common(pthread_rwlock_t *rwlock, int nonblocking, */ if (curthread->rwlockList != NULL) { LIST_FOREACH(rh, curthread->rwlockList, rh_link) { - if (rh->rh_rwlock == prwlock && - (rh->rh_rdcount > 0 || rh->rh_wrcount > 0)) { + if (rh->rh_rwlock == prwlock) { + PTHREAD_ASSERT((rh->rh_rdcount > 0 || + rh->rh_wrcount > 0), + "Invalid 0 R/RW count!"); pthread_mutex_unlock(&prwlock->lock); return (EDEADLK); break; @@ -462,16 +464,10 @@ rwlock_init_static(struct pthread_rwlock **rwlock) { int error; - /* - * The initial check is done without locks to not - * pessimize the common path. - */ error = 0; - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) { - UMTX_LOCK(&init_lock); - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - error = _pthread_rwlock_init(rwlock, NULL); - UMTX_UNLOCK(&init_lock); - } + UMTX_LOCK(&init_lock); + if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) + error = _pthread_rwlock_init(rwlock, NULL); + UMTX_UNLOCK(&init_lock); return (error); } diff --git a/lib/libthr/thread/thr_setschedparam.c b/lib/libthr/thread/thr_setschedparam.c index de4eeea..fff1abf 100644 --- a/lib/libthr/thread/thr_setschedparam.c +++ b/lib/libthr/thread/thr_setschedparam.c @@ -84,6 +84,7 @@ _pthread_setschedparam(pthread_t pthread, int policy, else break; } else { + mtx = NULL; break; } } while (1); |