From e0c2cac90822151dab7aefd9412b163b532552d6 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 18 Jun 2007 21:04:41 +0000 Subject: [PATCH] SILC_VERIFY mutex lock and unlock calls, and rwlock wrlock and unlock calls. --- lib/silcutil/silcmutex.h | 6 ++++-- lib/silcutil/unix/silcunixthread.c | 12 +++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/silcutil/silcmutex.h b/lib/silcutil/silcmutex.h index 070a2e9a..6e8efeb2 100644 --- a/lib/silcutil/silcmutex.h +++ b/lib/silcutil/silcmutex.h @@ -190,7 +190,7 @@ void silc_rwlock_free(SilcRwLock rwlock); * is locked by a writer the current thread will block until the other * thread has issued silc_rwlock_unlock for the `rwlock'. This function * may be called multiple times to acquire the read lock. There must be - * same amount of silc_rwlock_unlock calls. If `rwlock' is NULL this + * same number of silc_rwlock_unlock calls. If `rwlock' is NULL this * function has no effect. * ***/ @@ -207,7 +207,9 @@ void silc_rwlock_rdlock(SilcRwLock rwlock); * Acquires write lock of the read/write lock `rwlock'. If the `rwlock' * is locked by a writer or a reader the current thread will block until * the other thread(s) have issued silc_rwlock_unlock for the `rwlock'. - * If `rwlock' is NULL this function has no effect. + * A thread may acquire the write lock only once. A deadlock may occur + * if thread attempts to acquire the write lock when it has already done + * so. If `rwlock' is NULL this function has no effect. * ***/ void silc_rwlock_wrlock(SilcRwLock rwlock); diff --git a/lib/silcutil/unix/silcunixthread.c b/lib/silcutil/unix/silcunixthread.c index fbfb0da2..bd551c29 100644 --- a/lib/silcutil/unix/silcunixthread.c +++ b/lib/silcutil/unix/silcunixthread.c @@ -144,8 +144,7 @@ void silc_mutex_lock(SilcMutex mutex) { #ifdef SILC_THREADS if (mutex) { - if (pthread_mutex_lock(&mutex->mutex)) - SILC_ASSERT(FALSE); + SILC_VERIFY(pthread_mutex_lock(&mutex->mutex) == 0); mutex->locked = TRUE; } #endif /* SILC_THREADS */ @@ -155,8 +154,7 @@ void silc_mutex_unlock(SilcMutex mutex) { #ifdef SILC_THREADS if (mutex) { - if (pthread_mutex_unlock(&mutex->mutex)) - SILC_ASSERT(FALSE); + SILC_VERIFY(pthread_mutex_unlock(&mutex->mutex) == 0); mutex->locked = FALSE; } #endif /* SILC_THREADS */ @@ -166,7 +164,7 @@ void silc_mutex_assert_locked(SilcMutex mutex) { #ifdef SILC_THREADS if (mutex) - SILC_ASSERT(mutex->locked); + SILC_VERIFY(mutex->locked); #endif /* SILC_THREADS */ } @@ -216,7 +214,7 @@ void silc_rwlock_wrlock(SilcRwLock rwlock) { #ifdef SILC_THREADS if (rwlock) - pthread_rwlock_wrlock(&rwlock->rwlock); + SILC_VERIFY(pthread_rwlock_wrlock(&rwlock->rwlock) == 0); #endif /* SILC_THREADS */ } @@ -224,7 +222,7 @@ void silc_rwlock_unlock(SilcRwLock rwlock) { #ifdef SILC_THREADS if (rwlock) - pthread_rwlock_unlock(&rwlock->rwlock); + SILC_VERIFY(pthread_rwlock_unlock(&rwlock->rwlock) == 0); #endif /* SILC_THREADS */ } -- 2.24.0