X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Funix%2Fsilcunixthread.c;h=7f52de901daca7baafd9d1c1bca4aaf949e52ad3;hb=9905799a86c606304fd7df2cd401de1740a272a1;hp=3c5cb65904393e49d1e2089d47d03aa77a797060;hpb=3a4359b248742c4d08d00c06badcb346d4a19528;p=silc.git diff --git a/lib/silcutil/unix/silcunixthread.c b/lib/silcutil/unix/silcunixthread.c index 3c5cb659..7f52de90 100644 --- a/lib/silcutil/unix/silcunixthread.c +++ b/lib/silcutil/unix/silcunixthread.c @@ -104,9 +104,8 @@ SilcBool silc_thread_wait(SilcThread thread, void **exit_value) struct SilcMutexStruct { #ifdef SILC_THREADS pthread_mutex_t mutex; -#else - void *tmp; #endif /* SILC_THREADS */ + unsigned int locked : 1; }; SilcBool silc_mutex_alloc(SilcMutex *mutex) @@ -116,6 +115,7 @@ SilcBool silc_mutex_alloc(SilcMutex *mutex) if (*mutex == NULL) return FALSE; pthread_mutex_init(&(*mutex)->mutex, NULL); + (*mutex)->locked = FALSE; return TRUE; #else return FALSE; @@ -137,7 +137,8 @@ void silc_mutex_lock(SilcMutex mutex) #ifdef SILC_THREADS if (mutex) { if (pthread_mutex_lock(&mutex->mutex)) - assert(FALSE); + SILC_ASSERT(FALSE); + mutex->locked = TRUE; } #endif /* SILC_THREADS */ } @@ -147,13 +148,22 @@ void silc_mutex_unlock(SilcMutex mutex) #ifdef SILC_THREADS if (mutex) { if (pthread_mutex_unlock(&mutex->mutex)) - assert(FALSE); + SILC_ASSERT(FALSE); + mutex->locked = FALSE; } #endif /* SILC_THREADS */ } +void silc_mutex_assert_locked(SilcMutex mutex) +{ +#ifdef SILC_THREADS + if (mutex) + SILC_ASSERT(mutex->locked); +#endif /* SILC_THREADS */ +} + -/**************************** SILC Cond API ******************************/ +/****************************** SILC Cond API *******************************/ /* SILC Conditional Variable context */ struct SilcCondStruct { @@ -218,5 +228,7 @@ SilcBool silc_cond_timedwait(SilcCond cond, SilcMutex mutex, } return pthread_cond_wait(&cond->cond, &mutex->mutex) == 0; +#else + return FALSE; #endif /* SILC_THREADS*/ }