X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=lib%2Fsilcutil%2Fwin32%2Fsilcwin32mutex.c;h=09e8e90ab01774d1edd5db1f1d13d80cb14c85eb;hp=11c03c9c8e354ff7ca985f7f4a603f9e0412e9bd;hb=d1e71f42379e8b5cd0748a7aeae8561b02cfe53d;hpb=34bb35a2496ec0402bb4d6c2546147cd37b27007 diff --git a/lib/silcutil/win32/silcwin32mutex.c b/lib/silcutil/win32/silcwin32mutex.c index 11c03c9c..09e8e90a 100644 --- a/lib/silcutil/win32/silcwin32mutex.c +++ b/lib/silcutil/win32/silcwin32mutex.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 @@ -22,9 +21,9 @@ #include "silcincludes.h" /* SILC Mutex structure */ -struct SilcMutexStruct { +struct SilcMutexStruct { #ifdef SILC_THREADS - CRITICAL_SECTION mutex; + CRITICAL_SECTION mutex; BOOL locked; #else void *tmp; @@ -34,8 +33,8 @@ struct SilcMutexStruct { bool silc_mutex_alloc(SilcMutex *mutex) { #ifdef SILC_THREADS - *mutex = silc_calloc(1, sizeof(**mutex)); - InitializeCriticalSection(&((*mutex)->mutex)); + *mutex = silc_calloc(1, sizeof(**mutex)); + InitializeCriticalSection(&((*mutex)->mutex)); #endif /* SILC_THREADS */ return TRUE; } @@ -43,25 +42,31 @@ bool silc_mutex_alloc(SilcMutex *mutex) void silc_mutex_free(SilcMutex mutex) { #ifdef SILC_THREADS - DeleteCriticalSection(&mutex->mutex); - silc_free(mutex); + if (mutex) { + DeleteCriticalSection(&mutex->mutex); + silc_free(mutex); + } #endif /* SILC_THREADS */ } void silc_mutex_lock(SilcMutex mutex) { #ifdef SILC_THREADS - EnterCriticalSection(&mutex->mutex); - assert(mutex->locked == FALSE); - mutex->locked = TRUE; + if (mutex) { + EnterCriticalSection(&mutex->mutex); + assert(mutex->locked == FALSE); + mutex->locked = TRUE; + } #endif /* SILC_THREADS */ } void silc_mutex_unlock(SilcMutex mutex) { #ifdef SILC_THREADS - assert(mutex->locked == TRUE); - mutex->locked = FALSE; - LeaveCriticalSection(&mutex->mutex); + if (mutex) { + assert(mutex->locked == TRUE); + mutex->locked = FALSE; + LeaveCriticalSection(&mutex->mutex); + } #endif /* SILC_THREADS */ }