1 /* EINA - EFL data type library
2 * Copyright (C) 2011 Vincent Torri
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
19 #ifndef EINA_INLINE_LOCK_VOID_X_
20 #define EINA_INLINE_LOCK_VOID_X_
26 # define EINA_UNUSED __attribute__((unused))
32 * @addtogroup Eina_Lock_Group Lock
34 * @brief These functions provide Mutual Exclusion objects management.
36 * @note On Windows XP, critical sections are used, while on Windows
37 * CE, standard Mutex objects are used.
44 * Abtract type for a mutual exclusive object.
46 typedef void *Eina_Lock;
47 typedef void *Eina_RWLock;
48 typedef void *Eina_Condition;
49 typedef void *Eina_TLS;
50 typedef void *Eina_Semaphore;
53 * @brief Create a new #Eina_Lock.
55 * @param mutex A pointer to the lock object.
56 * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
58 * This function creates a new #Eina_Lock object and stores it in the
59 * @p mutex buffer. On success, this function returns #EINA_TRUE
60 * and #EINA_FALSE otherwise. To free the resources allocated by this
61 * function, use eina_lock_free(). For performance reasons, no check
62 * is done on @p mutex.
64 static inline Eina_Bool
65 eina_lock_new(Eina_Lock *mutex EINA_UNUSED)
71 * @brief Free the ressources of the given lock object.
73 * @param mutex The lock object to free.
75 * This function frees the resources of @p mutex allocated by
76 * eina_lock_new(). For performance reasons, no check is done on
80 eina_lock_free(Eina_Lock *mutex EINA_UNUSED)
85 * @brief Lock the given mutual exclusion object.
87 * @param mutex The lock object to lock.
88 * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
90 * This function locks @p mutex. @p mutex must have been created by
91 * eina_lock_new(). On success, this function returns #EINA_TRUE
92 * and #EINA_FALSE otherwise. For performance reasons, no check is done on
95 static inline Eina_Lock_Result
96 eina_lock_take(Eina_Lock *mutex EINA_UNUSED)
98 return EINA_LOCK_SUCCEED;
102 * @brief Try to lock the given mutual exclusion object.
104 * @param mutex The lock object to try to lock.
105 * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
107 * This function tries to lock @p mutex. @p mutex must have been created by
108 * eina_lock_new(). If @p mutex can be locked, this function returns #EINA_TRUE;
109 * if @p mutex can not be locked, or is already locked, it
110 * returns #EINA_FALSE. This function does not block and returns
111 * immediately. For performance reasons, no check is done on
114 * @note On Windows CE, this function is actually eina_lock_take().
116 static inline Eina_Lock_Result
117 eina_lock_take_try(Eina_Lock *mutex EINA_UNUSED)
119 return EINA_LOCK_SUCCEED;
123 * @brief Unlock the given mutual exclusion object.
125 * @param mutex The lock object to unlock.
126 * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
128 * This function unlocks @p mutex. @p mutex must have been created by
129 * eina_lock_new(). On success, this function returns #EINA_TRUE
130 * and #EINA_FALSE otherwise. For performance reasons, no check is
133 static inline Eina_Lock_Result
134 eina_lock_release(Eina_Lock *mutex EINA_UNUSED)
136 return EINA_LOCK_SUCCEED;
140 eina_lock_debug(const Eina_Lock *mutex EINA_UNUSED)
144 static inline Eina_Bool
145 eina_condition_new(Eina_Condition *cond EINA_UNUSED, Eina_Lock *mutex EINA_UNUSED)
151 eina_condition_free(Eina_Condition *cond EINA_UNUSED)
155 static inline Eina_Bool
156 eina_condition_wait(Eina_Condition *cond EINA_UNUSED)
161 static inline Eina_Bool
162 eina_condition_timedwait(Eina_Condition *cond EINA_UNUSED, double val EINA_UNUSED)
167 static inline Eina_Bool
168 eina_condition_broadcast(Eina_Condition *cond EINA_UNUSED)
173 static inline Eina_Bool
174 eina_condition_signal(Eina_Condition *cond EINA_UNUSED)
179 static inline Eina_Bool
180 eina_rwlock_new(Eina_RWLock *mutex EINA_UNUSED)
186 eina_rwlock_free(Eina_RWLock *mutex EINA_UNUSED)
190 static inline Eina_Lock_Result
191 eina_rwlock_read_take(Eina_RWLock *mutex EINA_UNUSED)
193 return EINA_LOCK_SUCCEED;
196 static inline Eina_Lock_Result
197 eina_rwlock_write_take(Eina_RWLock *mutex EINA_UNUSED)
199 return EINA_LOCK_SUCCEED;
202 static inline Eina_Lock_Result
203 eina_rwlock_release(Eina_RWLock *mutex EINA_UNUSED)
205 return EINA_LOCK_SUCCEED;
208 static inline Eina_Lock_Result
209 eina_rwlock_take_read(Eina_RWLock *mutex EINA_UNUSED)
211 return EINA_LOCK_SUCCEED;
214 static inline Eina_Lock_Result
215 eina_rwlock_take_write(Eina_RWLock *mutex EINA_UNUSED)
217 return EINA_LOCK_SUCCEED;
220 static inline Eina_Bool
221 eina_tls_new(Eina_TLS *key EINA_UNUSED)
227 eina_tls_free(Eina_TLS key EINA_UNUSED)
232 eina_tls_get(Eina_TLS key EINA_UNUSED)
237 static inline Eina_Bool
238 eina_tls_set(Eina_TLS key EINA_UNUSED, const void *data EINA_UNUSED)
243 static inline Eina_Bool
244 eina_semaphore_new(Eina_Semaphore *sem EINA_UNUSED,
245 int count_init EINA_UNUSED)
250 static inline Eina_Bool
251 eina_semaphore_free(Eina_Semaphore *sem EINA_UNUSED)
256 static inline Eina_Bool
257 eina_semaphore_lock(Eina_Semaphore *sem EINA_UNUSED)
262 static inline Eina_Bool
263 eina_semaphore_release(Eina_Semaphore *sem EINA_UNUSED,
264 int count_release EINA_UNUSED)