X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Funix%2Fsilcunixmutex.c;h=0eae1496ce99ae6162ddb91e6896e1959eec045d;hb=40f8443d8d3a6577336ee66d18e04d9ac4d956bb;hp=c6b21573344c2b5665a8f986f0f508fdbec50cfb;hpb=f395181bb98a377bb6bdd899a36a6b12f02a3eb7;p=silc.git diff --git a/lib/silcutil/unix/silcunixmutex.c b/lib/silcutil/unix/silcunixmutex.c index c6b21573..0eae1496 100644 --- a/lib/silcutil/unix/silcunixmutex.c +++ b/lib/silcutil/unix/silcunixmutex.c @@ -4,13 +4,12 @@ Author: Pekka Riikonen - Copyright (C) 2001 Pekka Riikonen + Copyright (C) 2001 - 2005 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - + the Free Software Foundation; version 2 of the License. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -19,37 +18,56 @@ */ /* $Id$ */ -#include "silcincludes.h" - -#ifdef SILC_THREADS +#include "silc.h" /* SILC Mutex structure */ struct SilcMutexStruct { +#ifdef SILC_THREADS pthread_mutex_t mutex; +#else + void *tmp; +#endif /* SILC_THREADS */ }; -SilcMutex silc_mutex_alloc(void) +SilcBool silc_mutex_alloc(SilcMutex *mutex) { - SilcMutex mutex = silc_calloc(1, sizeof(*mutex)); - pthread_mutex_init(&mutex->mutex, NULL); +#ifdef SILC_THREADS + *mutex = silc_calloc(1, sizeof(**mutex)); + if (*mutex == NULL) + return FALSE; + pthread_mutex_init(&(*mutex)->mutex, NULL); + return TRUE; +#else + return FALSE; +#endif /* SILC_THREADS */ } void silc_mutex_free(SilcMutex mutex) { - pthread_mutex_destroy(&mutex->mutex); - silc_free(mutex); +#ifdef SILC_THREADS + if (mutex) { + pthread_mutex_destroy(&mutex->mutex); + silc_free(mutex); + } +#endif /* SILC_THREADS */ } void silc_mutex_lock(SilcMutex mutex) { - if (pthread_mutex_lock(&mutex->mutex)) - assert(FALSE); +#ifdef SILC_THREADS + if (mutex) { + if (pthread_mutex_lock(&mutex->mutex)) + assert(FALSE); + } +#endif /* SILC_THREADS */ } void silc_mutex_unlock(SilcMutex mutex) { - if (pthread_mutex_unlock(&mutex->mutex)) - assert(FALSE); -} - +#ifdef SILC_THREADS + if (mutex) { + if (pthread_mutex_unlock(&mutex->mutex)) + assert(FALSE); + } #endif /* SILC_THREADS */ +}