addition of silc.css
[silc.git] / lib / silcutil / unix / silcunixmutex.c
1 /*
2
3   silcunixmutex.c
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2001 Pekka Riikonen
8
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; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20 /* $Id$ */
21
22 #include "silcincludes.h"
23
24 #ifdef SILC_THREADS
25
26 /* SILC Mutex structure */
27 struct SilcMutexStruct {
28   pthread_mutex_t mutex;
29 };
30
31 bool silc_mutex_alloc(SilcMutex *mutex)
32 {
33   *mutex = silc_calloc(1, sizeof(**mutex));
34   if (*mutex == NULL)
35     return FALSE;
36
37   pthread_mutex_init(&(*mutex)->mutex, NULL);
38   return TRUE;
39 }
40
41 void silc_mutex_free(SilcMutex mutex)
42 {
43   pthread_mutex_destroy(&mutex->mutex);
44   silc_free(mutex);
45 }
46
47 void silc_mutex_lock(SilcMutex mutex)
48 {
49   if (pthread_mutex_lock(&mutex->mutex))
50     assert(FALSE);
51 }
52
53 void silc_mutex_unlock(SilcMutex mutex)
54 {
55   if (pthread_mutex_unlock(&mutex->mutex))
56     assert(FALSE);
57 }
58
59 #endif /* SILC_THREADS */