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.
20 /****h* silcutil/SILC Mutex Interface
24 * Interface for the SILC Mutex locking implementation. This is platform
25 * independent mutual exclusion interface for applications that need
26 * concurrency control.
33 /****s* silcutil/SilcMutexAPI/SilcMutex
37 * typedef struct SilcMutexStruct *SilcMutex;
41 * This context is the actual SILC Mutex and is allocated
42 * by silc_mutex_alloc and given as argument to all silc_mutex_*
43 * functions. It is freed by the silc_mutex_free function.
46 typedef struct SilcMutexStruct *SilcMutex;
48 /****f* silcutil/SilcMutexAPI/silc_mutex_alloc
52 * SilcBool silc_mutex_alloc(SilcMutex *mutex);
56 * Allocates SILC Mutex object. The mutex object must be allocated
57 * before it can be used. It is freed by the silc_mutex_free function.
58 * This returns TRUE and allocated mutex in to the `mutex' and FALSE
62 SilcBool silc_mutex_alloc(SilcMutex *mutex);
64 /****f* silcutil/SilcMutexAPI/silc_mutex_free
68 * void silc_mutex_free(SilcMutex mutex);
72 * Free SILC Mutex object and frees all allocated memory. If `mutex'
73 * is NULL this function has no effect.
76 void silc_mutex_free(SilcMutex mutex);
78 /****f* silcutil/SilcMutexAPI/silc_mutex_lock
82 * void silc_mutex_lock(SilcMutex mutex);
86 * Locks the mutex. If the mutex is locked by another thread the
87 * current thread will block until the other thread has issued
88 * silc_mutex_unlock for the mutex. If `mutex' is NULL this function
93 * The caller must not call silc_mutex_lock for mutex that has been
94 * already locked in the current thread. In this case deadlock will
98 void silc_mutex_lock(SilcMutex mutex);
100 /****f* silcutil/SilcMutexAPI/silc_mutex_unlock
104 * void silc_mutex_unlock(SilcMutex mutex);
108 * Unlocks the mutex and thus releases it for another thread that
109 * may be waiting for the lock. If `mutex' is NULL this function
114 * The caller must not call the silc_mutex_unlock for an unlocked
115 * mutex or mutex not locked by the current thread.
118 void silc_mutex_unlock(SilcMutex mutex);
120 /****f* silcutil/SilcMutexAPI/silc_mutex_assert_locked
124 * void silc_mutex_assert_locked(SilcMutex mutex);
128 * Asserts that the `mutex' is locked. It is fatal error if the mutex
129 * is not locked. If debugging is not compiled in this function has
130 * no effect (SILC_DEBUG define).
133 void silc_mutex_assert_locked(SilcMutex mutex);