Added SILC Thread Queue API
[silc.git] / lib / silcutil / beos / silcbeosmutex.c
index 74544928168df26ecbfb9c3f21c3ece9fc5507c6..2e1cef0cb7f6818518b419905b16fea58b6236a0 100644 (file)
   GNU General Public License for more details.
 
 */
+/* I used Apache's APR code as a reference here. */
 /* $Id$ */
 
-#include "silcincludes.h"
+#include "silc.h"
 
 #ifdef SILC_THREADS
 
 /* SILC Mutex structure */
 struct SilcMutexStruct {
-  int sema_count;
   sem_id sema;
 };
 
-bool silc_mutex_alloc(SilcMutex *mutex)
+SilcBool silc_mutex_alloc(SilcMutex *mutex)
 {
   int ret;
 
@@ -42,7 +42,6 @@ bool silc_mutex_alloc(SilcMutex *mutex)
     return FALSE;
   }
 
-  (*mutex)->sema_count = 0;
   (*mutex)->sema = ret;
 
   return TRUE;
@@ -56,18 +55,14 @@ void silc_mutex_free(SilcMutex mutex)
 
 void silc_mutex_lock(SilcMutex mutex)
 {
-  if (atomic_add(&mutex->sema_count, 1) > 0) {
-    if (acquire_sem(mutex->sema) < B_NO_ERROR)
-      assert(FALSE);
-  }
+  if (acquire_sem(mutex->sema) < B_NO_ERROR)
+    assert(FALSE);
 }
 
 void silc_mutex_unlock(SilcMutex mutex)
 {
-  if (atomic_add(&mutes->sema_count, -1) > 1) {
-    if (release_sem(mutex->sema) < B_NO_ERROR)
-      assert(FALSE);
-  }
+  if (release_sem(mutex->sema) < B_NO_ERROR)
+    assert(FALSE);
 }
 
 #endif /* SILC_THREADS */