Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_lock.h
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Lock Support
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 #ifndef __AFW_LOCK_H__
10 #define __AFW_LOCK_H__
11 
12 #include "afw_interface.h"
13 
28 
30 typedef enum {
31  afw_lock_type_global_mutex,
32  afw_lock_type_process_mutex,
33  afw_lock_type_thread_mutex,
34  afw_lock_type_thread_recursive_mutex,
35  afw_lock_type_thread_read_write
37 
38 
43 struct afw_lock_s {
44  const afw_utf8_t *lock_id;
45  const afw_utf8_t *brief;
46  const afw_utf8_t *description;
47  const afw_utf8_t *flag_id_debug;
48  afw_size_t flag_index_debug;
49  union {
50 
52  apr_thread_mutex_t *mutex;
53 
55  apr_thread_rwlock_t *rwlock;
56  };
57  afw_lock_type_t lock_type;
58 };
59 
60 
69 struct afw_lock_rw_s {
70  struct afw_lock_s lock;
71 };
72 
73 
82 AFW_DECLARE(const afw_lock_t *)
84  const afw_utf8_t *lock_id,
85  const afw_utf8_t *brief,
86  const afw_utf8_t *description,
87  afw_boolean_t insure_recursive_lock,
88  const afw_pool_t *p,
89  afw_xctx_t *xctx);
90 
91 
99 AFW_DECLARE(const afw_lock_t *)
101  const afw_utf8_t *lock_id,
102  const afw_utf8_t *brief,
103  const afw_utf8_t *description,
104  afw_boolean_t insure_recursive_lock,
105  afw_xctx_t *xctx);
106 
107 
115 AFW_DECLARE(const afw_lock_t *)
116 afw_lock_create_environment_lock(
117  const afw_utf8_t *lock_id,
118  const afw_pool_t *p,
119  afw_xctx_t *xctx);
120 
121 
129 AFW_DECLARE(void)
130 afw_lock_obtain(const afw_lock_t *instance, afw_xctx_t *xctx);
131 
132 
140 AFW_DECLARE(void)
141 afw_lock_obtain_debug(const afw_lock_t *instance,
142  afw_xctx_t *xctx, const afw_utf8_z_t *source_z);
143 
144 
145 #ifdef AFW_LOCK_DEBUG
146 #define afw_lock_obtain(instance,xctx) \
147  afw_lock_obtain_debug(instance, xctx, AFW__FILE_LINE__)
148 #endif
149 
150 
156 AFW_DECLARE(void)
157 afw_lock_release(const afw_lock_t *instance, afw_xctx_t *xctx);
158 
159 
167 AFW_DECLARE(void)
168 afw_lock_release_debug(const afw_lock_t *instance,
169  afw_xctx_t *xctx, const afw_utf8_z_t *source_z);
170 
171 
172 #ifdef AFW_LOCK_DEBUG
173 #define afw_lock_release(instance,xctx) \
174  afw_lock_release_debug(instance, xctx, AFW__FILE_LINE__)
175 #endif
176 
177 
191 #define AFW_LOCK_BEGIN(instance) \
192 const afw_lock_t *this_LOCK = instance; \
193 afw_lock_obtain(this_LOCK, xctx); \
194 AFW_TRY
195 
196 
202 #define AFW_LOCK_END \
203 AFW_FINALLY { \
204  afw_lock_release(this_LOCK, xctx); \
205 } \
206 AFW_ENDTRY
207 
208 
209 
216 AFW_DECLARE(const afw_lock_rw_t *)
218  const afw_utf8_t *lock_id,
219  const afw_utf8_t *brief,
220  const afw_utf8_t *description,
221  const afw_pool_t *p,
222  afw_xctx_t *xctx);
223 
224 
225 
231 AFW_DECLARE(const afw_lock_rw_t *)
233  const afw_utf8_t *lock_id,
234  const afw_utf8_t *brief,
235  const afw_utf8_t *description,
236  afw_xctx_t *xctx);
237 
238 
239 
247 AFW_DECLARE(void)
248 afw_lock_read_obtain(const afw_lock_rw_t *instance, afw_xctx_t *xctx);
249 
250 
258 AFW_DECLARE(void)
260  afw_xctx_t *xctx, const afw_utf8_z_t *source_z);
261 
262 
263 #ifdef AFW_LOCK_DEBUG
264 #define afw_lock_read_obtain(instance,xctx) \
265  afw_lock_read_obtain_debug(instance, xctx, AFW__FILE_LINE__)
266 #endif
267 
268 
274 AFW_DECLARE(void)
275 afw_lock_read_release(const afw_lock_rw_t *instance, afw_xctx_t *xctx);
276 
277 
285 AFW_DECLARE(void)
287  afw_xctx_t *xctx, const afw_utf8_z_t *source_z);
288 
289 
290 #ifdef AFW_LOCK_DEBUG
291 #define afw_lock_read_release(instance,xctx) \
292  afw_lock_read_release_debug(instance, xctx, AFW__FILE_LINE__)
293 #endif
294 
295 
309 #define AFW_LOCK_READ_BEGIN(instance) \
310 const afw_lock_rw_t *this_LOCK = instance; \
311  afw_lock_read_obtain(this_LOCK, xctx); \
312 AFW_TRY
313 
314 
320 #define AFW_LOCK_READ_END \
321 AFW_FINALLY { \
322  afw_lock_read_release(this_LOCK, xctx); \
323 } \
324 AFW_ENDTRY
325 
326 
327 
335 AFW_DECLARE(void)
336 afw_lock_write_obtain(const afw_lock_rw_t *instance, afw_xctx_t *xctx);
337 
338 
346 AFW_DECLARE(void)
348  afw_xctx_t *xctx, const afw_utf8_z_t *source_z);
349 
350 
351 #ifdef AFW_LOCK_DEBUG
352 #define afw_lock_write_obtain(instance,xctx) \
353  afw_lock_write_obtain_debug(instance, xctx, AFW__FILE_LINE__)
354 #endif
355 
356 
365 AFW_DECLARE(void)
366 afw_lock_write_release(const afw_lock_rw_t *instance, afw_xctx_t *xctx);
367 
368 
376 AFW_DECLARE(void)
378  afw_xctx_t *xctx, const afw_utf8_z_t *source_z);
379 
380 
381 #ifdef AFW_LOCK_DEBUG
382 #define afw_lock_write_release(instance,xctx) \
383  afw_lock_write_release_debug(instance, xctx, AFW__FILE_LINE__)
384 #endif
385 
386 
400 #define AFW_LOCK_WRITE_BEGIN(instance) \
401 const afw_lock_rw_t *this_LOCK = instance; \
402  afw_lock_write_obtain(this_LOCK, xctx); \
403 AFW_TRY
404 
405 
411 #define AFW_LOCK_WRITE_END \
412 AFW_FINALLY { \
413  afw_lock_write_release(this_LOCK, xctx); \
414 } \
415 AFW_ENDTRY
416 
417 AFW_END_DECLARES
418 
421 #endif /* __AFW_LOCK_H__ */
#define AFW_BEGIN_DECLARES
#define AFW_DECLARE(type)
Declare a public afw function.
Interfaceafw_interface header.
_Bool afw_boolean_t
Definition: afw_common.h:373
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
Definition: afw_common.h:523
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
void afw_lock_write_obtain_debug(const afw_lock_rw_t *instance, afw_xctx_t *xctx, const afw_utf8_z_t *source_z)
Debug version of obtain write lock.
Definition: afw_lock.c:422
const afw_lock_rw_t * afw_lock_create_rw_and_register(const afw_utf8_t *lock_id, const afw_utf8_t *brief, const afw_utf8_t *description, afw_xctx_t *xctx)
Create a read/write lock and register in environment.
Definition: afw_lock.c:175
void afw_lock_release(const afw_lock_t *instance, afw_xctx_t *xctx)
Release lock.
Definition: afw_lock.c:291
const afw_lock_t * afw_lock_create_and_register(const afw_utf8_t *lock_id, const afw_utf8_t *brief, const afw_utf8_t *description, afw_boolean_t insure_recursive_lock, afw_xctx_t *xctx)
Create a lock and register in environment.
Definition: afw_lock.c:73
void afw_lock_release_debug(const afw_lock_t *instance, afw_xctx_t *xctx, const afw_utf8_z_t *source_z)
Debug version of release lock.
Definition: afw_lock.c:310
void afw_lock_read_release(const afw_lock_rw_t *instance, afw_xctx_t *xctx)
Release read lock.
Definition: afw_lock.c:366
void afw_lock_write_release(const afw_lock_rw_t *instance, afw_xctx_t *xctx)
Release write lock.
Definition: afw_lock.c:438
void afw_lock_write_obtain(const afw_lock_rw_t *instance, afw_xctx_t *xctx)
Obtain write lock.
Definition: afw_lock.c:403
const afw_lock_rw_t * afw_lock_create_rw(const afw_utf8_t *lock_id, const afw_utf8_t *brief, const afw_utf8_t *description, const afw_pool_t *p, afw_xctx_t *xctx)
Create a read/write lock that will last for life of pool.
Definition: afw_lock.c:192
void afw_lock_read_obtain_debug(const afw_lock_rw_t *instance, afw_xctx_t *xctx, const afw_utf8_z_t *source_z)
Debug version of obtain read lock.
Definition: afw_lock.c:347
void afw_lock_obtain(const afw_lock_t *instance, afw_xctx_t *xctx)
Obtain lock.
Definition: afw_lock.c:254
void afw_lock_write_release_debug(const afw_lock_rw_t *instance, afw_xctx_t *xctx, const afw_utf8_z_t *source_z)
Debug version of release write lock.
Definition: afw_lock.c:457
void afw_lock_read_obtain(const afw_lock_rw_t *instance, afw_xctx_t *xctx)
Obtain read lock.
Definition: afw_lock.c:328
void afw_lock_read_release_debug(const afw_lock_rw_t *instance, afw_xctx_t *xctx, const afw_utf8_z_t *source_z)
Debug version of release read lock.
Definition: afw_lock.c:385
void afw_lock_obtain_debug(const afw_lock_t *instance, afw_xctx_t *xctx, const afw_utf8_z_t *source_z)
Debug version of obtain lock.
Definition: afw_lock.c:273
const afw_lock_t * afw_lock_create(const afw_utf8_t *lock_id, const afw_utf8_t *brief, const afw_utf8_t *description, afw_boolean_t insure_recursive_lock, const afw_pool_t *p, afw_xctx_t *xctx)
Create a lock that will last for life of pool.
Definition: afw_lock.c:92
afw_lock_type_t
Lock type.
Definition: afw_lock.h:30
apr_thread_rwlock_t * rwlock
for type thread_read_write
Definition: afw_lock.h:55
apr_thread_mutex_t * mutex
for type thread_mutex
Definition: afw_lock.h:52
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.