ua_util.h 860 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef UA_UTIL_H_
  2. #define UA_UTIL_H_
  3. #include "ua_config.h"
  4. /* Assert */
  5. #include <assert.h>
  6. #define UA_assert(ignore) assert(ignore)
  7. /* container_of */
  8. #define container_of(ptr, type, member) \
  9. (type *)((uintptr_t)ptr - offsetof(type,member))
  10. /* Thread Local Storage */
  11. #ifdef UA_ENABLE_MULTITHREADING
  12. # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
  13. # define UA_THREAD_LOCAL _Thread_local /* C11 */
  14. # elif defined(__GNUC__)
  15. # define UA_THREAD_LOCAL __thread /* GNU extension */
  16. # elif defined(_MSC_VER)
  17. # define UA_THREAD_LOCAL __declspec(thread) /* MSVC extension */
  18. # else
  19. # warning The compiler does not allow thread-local variables. The library can be built, but will not be thread-safe.
  20. # endif
  21. #endif
  22. #ifndef UA_THREAD_LOCAL
  23. # define UA_THREAD_LOCAL
  24. #endif
  25. /* BSD Queue Macros */
  26. #include "queue.h"
  27. #endif /* UA_UTIL_H_ */