1 /****h* silcutil/silcmutex.h
9 * Author: Pekka Riikonen <priikone@silcnet.org>
11 * Copyright (C) 2001 Pekka Riikonen
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
25 * Interface for the SILC Mutex locking implementation. This is platform
26 * independent mutual exclusion interface for applications that need
27 * concurrency control.
36 /****s* silcutil/SilcMutexAPI/SilcMutex
40 * typedef struct SilcMutexStruct *SilcMutex;
44 * This context is the actual SILC Mutex and is allocated
45 * by silc_mutex_alloc and given as argument to all silc_mutex_*
46 * functions. It is freed by the silc_mutex_free function.
49 typedef struct SilcMutexStruct *SilcMutex;
51 /****d* silcutil/SilcMutexAPI/SILC_MUTEX_DEFINE
55 * #define SILC_MUTEX_DEFINE(name) ...
59 * This macro is used to define new mutex. Use this macro in an
60 * environment that can be compiled with or without the SILC Mutex
61 * API. This is equivalent to defining SilcMutex `name'; directly.
65 #define SILC_MUTEX_DEFINE(name) SilcMutex name
68 /****f* silcutil/SilcMutexAPI/silc_mutex_alloc
72 * SilcMutex silc_mutex_alloc(void);
76 * Allocates SILC Mutex object. The mutex object must be allocated
77 * before it can be used. It is freed by the silc_mutex_free function.
80 SilcMutex silc_mutex_alloc(void);
82 /****f* silcutil/SilcMutexAPI/silc_mutex_free
86 * void silc_mutex_free(SilcMutex mutex);
90 * Free SILC Mutex object and frees all allocated memory.
93 void silc_mutex_free(SilcMutex mutex);
95 /****f* silcutil/SilcMutexAPI/silc_mutex_lock
99 * void silc_mutex_lock(SilcMutex mutex);
103 * Locks the mutex. If the mutex is locked by another thread the
104 * current thread will block until the other thread has issued
105 * silc_mutex_unlock for the mutex.
109 * The caller must not call silc_mutex_lock for mutex that has been
110 * already locked in the current thread. In this case deadlock will
114 void silc_mutex_lock(SilcMutex mutex);
116 /****f* silcutil/SilcMutexAPI/silc_mutex_unlock
120 * void silc_mutex_unlock(SilcMutex mutex);
124 * Unlocks the mutex and thus releases it for another thread that
125 * may be waiting for the lock.
129 * The caller must not call the silc_mutex_unlock for an unlocked
130 * mutex or mutex not locked by the current thread. It is fatal
131 * error if this occurs.
134 void silc_mutex_unlock(SilcMutex mutex);
138 #define SILC_MUTEX_DEFINE(name)
139 #define silc_mutex_alloc()
140 #define silc_mutex_free(mutex)
141 #define silc_mutex_lock(mutex)
142 #define silc_mutex_unlock(mutex)
144 #endif /* SILC_THREADS */