24#ifndef COAP_THREADSAFE_INTERNAL_H_
25#define COAP_THREADSAFE_INTERNAL_H_
94# if COAP_THREAD_RECURSIVE_CHECK
102 const char *lock_file;
103 unsigned int lock_line;
104 unsigned int unlock_line;
105 const char *unlock_file;
106 const char *callback_file;
107 unsigned int callback_line;
108 unsigned int in_callback;
109 unsigned int lock_count;
123void coap_lock_unlock_func(
const char *file,
int line);
138int coap_lock_lock_func(
const char *file,
int line);
156#define coap_lock_lock(c,failed) do { \
157 if (!coap_lock_lock_func(__FILE__, __LINE__)) { \
171#define coap_lock_unlock(c) do { \
172 coap_lock_unlock_func(__FILE__, __LINE__); \
185#define coap_lock_callback(c,func) do { \
186 coap_lock_check_locked(c); \
187 global_lock.in_callback++; \
188 global_lock.callback_file = __FILE__; \
189 global_lock.callback_line = __LINE__; \
191 global_lock.in_callback--; \
206#define coap_lock_callback_ret(r,c,func) do { \
207 coap_lock_check_locked(c); \
208 global_lock.in_callback++; \
209 global_lock.callback_file = __FILE__; \
210 global_lock.callback_line = __LINE__; \
212 global_lock.in_callback--; \
226#define coap_lock_callback_release(c,func,failed) do { \
227 coap_lock_check_locked(c); \
228 coap_lock_unlock(c); \
230 coap_lock_lock(c,failed); \
246#define coap_lock_callback_ret_release(r,c,func,failed) do { \
247 coap_lock_check_locked(c); \
248 coap_lock_unlock(c); \
250 coap_lock_lock(c,failed); \
263 uint32_t in_callback;
264 volatile uint32_t lock_count;
276void coap_lock_unlock_func(
void);
288int coap_lock_lock_func(
void);
306#define coap_lock_lock(c,failed) do { \
307 if (!coap_lock_lock_func()) { \
321#define coap_lock_unlock(c) do { \
323 coap_lock_unlock_func(); \
336#define coap_lock_callback(c,func) do { \
337 coap_lock_check_locked(c); \
338 global_lock.in_callback++; \
340 global_lock.in_callback--; \
355#define coap_lock_callback_ret(r,c,func) do { \
356 coap_lock_check_locked(c); \
357 global_lock.in_callback++; \
358 global_lock.in_callback++; \
360 global_lock.in_callback--; \
374#define coap_lock_callback_release(c,func,failed) do { \
375 coap_lock_check_locked(c); \
376 coap_lock_unlock(c); \
378 coap_lock_lock(c,failed); \
394#define coap_lock_callback_ret_release(r,c,func,failed) do { \
395 coap_lock_check_locked(c); \
396 coap_lock_unlock(c); \
398 coap_lock_lock(c,failed); \
406#define coap_lock_init() do { \
407 memset(&global_lock.mutex, 0, sizeof(global_lock.mutex)); \
408 coap_mutex_init(&global_lock.mutex); \
414#define coap_lock_check_locked(c) do { \
415 assert(coap_thread_pid == global_lock.pid); \
431#define coap_lock_invert(c,alt_lock,failed) do { \
432 coap_lock_check_locked(c); \
433 coap_lock_unlock(c); \
435 coap_lock_lock(c,failed); \
465#define coap_lock_lock(c,failed)
477#define coap_lock_unlock(c)
484#define coap_lock_init()
491#define coap_lock_check_locked(c) {}
505#define coap_lock_callback(c,func) func
521#define coap_lock_callback_ret(r,c,func) (r) = func
536#define coap_lock_callback_release(c,func,failed) func
554#define coap_lock_callback_ret_release(r,c,func,failed) (r) = func
571#define coap_lock_invert(c,alt_lock,failed) func
#define coap_thread_pid_t