SILC_VERIFY mutex lock and unlock calls, and rwlock wrlock and
authorPekka Riikonen <priikone@silcnet.org>
Mon, 18 Jun 2007 21:04:41 +0000 (21:04 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 18 Jun 2007 21:04:41 +0000 (21:04 +0000)
unlock calls.

lib/silcutil/silcmutex.h
lib/silcutil/unix/silcunixthread.c

index 070a2e9a3e0e774e5e0934cb084eb0680efb1ed4..6e8efeb2b7dfd807ed63d9696f005351bb23d3bf 100644 (file)
@@ -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);
index fbfb0da254c697596f9f2c4ee75fbbaf52c47bac..bd551c2990ac4e5a449c7e38ec686c4f80aa705a 100644 (file)
@@ -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 */
 }