5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2001 - 2005 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
23 /* SILC Mutex structure */
24 struct SilcMutexStruct {
26 CRITICAL_SECTION mutex;
30 #endif /* SILC_THREADS */
33 SilcBool silc_mutex_alloc(SilcMutex *mutex)
36 *mutex = silc_calloc(1, sizeof(**mutex));
39 InitializeCriticalSection(&((*mutex)->mutex));
43 #endif /* SILC_THREADS */
46 void silc_mutex_free(SilcMutex mutex)
50 DeleteCriticalSection(&mutex->mutex);
53 #endif /* SILC_THREADS */
56 void silc_mutex_lock(SilcMutex mutex)
60 EnterCriticalSection(&mutex->mutex);
61 assert(mutex->locked == FALSE);
64 #endif /* SILC_THREADS */
67 void silc_mutex_unlock(SilcMutex mutex)
71 assert(mutex->locked == TRUE);
72 mutex->locked = FALSE;
73 LeaveCriticalSection(&mutex->mutex);
75 #endif /* SILC_THREADS */