X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Funix%2Fsilcunixmutex.c;h=1336eaeea7d57592db62d2983d3f4dda6efca471;hb=d1e71f42379e8b5cd0748a7aeae8561b02cfe53d;hp=d6eb0f233f973dd63e51d183b29b5ad577fb4696;hpb=34bb35a2496ec0402bb4d6c2546147cd37b27007;p=crypto.git diff --git a/lib/silcutil/unix/silcunixmutex.c b/lib/silcutil/unix/silcunixmutex.c index d6eb0f23..1336eaee 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 @@ -45,27 +44,33 @@ bool silc_mutex_alloc(SilcMutex *mutex) void silc_mutex_free(SilcMutex mutex) { #ifdef SILC_THREADS - pthread_mutex_destroy(&mutex->mutex); - silc_free(mutex); + if (mutex) { + pthread_mutex_destroy(&mutex->mutex); + silc_free(mutex); + } #endif /* SILC_THREADS */ } void silc_mutex_lock(SilcMutex mutex) { #ifdef SILC_THREADS - if (pthread_mutex_lock(&mutex->mutex)) - assert(FALSE); - assert(mutex->locked == 0); - mutex->locked = 1; + if (mutex) { + if (pthread_mutex_lock(&mutex->mutex)) + assert(FALSE); + assert(mutex->locked == 0); + mutex->locked = 1; + } #endif /* SILC_THREADS */ } void silc_mutex_unlock(SilcMutex mutex) { #ifdef SILC_THREADS - assert(mutex->locked == 1); - mutex->locked = 0; - if (pthread_mutex_unlock(&mutex->mutex)) - assert(FALSE); + if (mutex) { + assert(mutex->locked == 1); + mutex->locked = 0; + if (pthread_mutex_unlock(&mutex->mutex)) + assert(FALSE); + } #endif /* SILC_THREADS */ }