ua_util.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef UA_UTIL_H_
  2. #define UA_UTIL_H_
  3. #include "ua_config.h"
  4. /* Subtract from nodeids to get from the encoding to the content */
  5. #define UA_ENCODINGOFFSET_XML 1
  6. #define UA_ENCODINGOFFSET_BINARY 2
  7. #include <assert.h> // assert
  8. #define UA_assert(ignore) assert(ignore)
  9. /*********************/
  10. /* Memory Management */
  11. /*********************/
  12. /* Replace the macros with functions for custom allocators if necessary */
  13. #include <stdlib.h> // malloc, free
  14. #ifdef _WIN32
  15. # include <malloc.h>
  16. #endif
  17. #ifndef UA_free
  18. # define UA_free(ptr) free(ptr)
  19. #endif
  20. #ifndef UA_malloc
  21. # define UA_malloc(size) malloc(size)
  22. #endif
  23. #ifndef UA_calloc
  24. # define UA_calloc(num, size) calloc(num, size)
  25. #endif
  26. #ifndef UA_realloc
  27. # define UA_realloc(ptr, size) realloc(ptr, size)
  28. #endif
  29. #ifndef NO_ALLOCA
  30. # ifdef __GNUC__
  31. # define UA_alloca(size) __builtin_alloca (size)
  32. # elif defined(_WIN32)
  33. # define UA_alloca(SIZE) _alloca(SIZE)
  34. # else
  35. # include <alloca.h>
  36. # define UA_alloca(SIZE) alloca(SIZE)
  37. # endif
  38. #endif
  39. /************************/
  40. /* Thread Local Storage */
  41. /************************/
  42. #ifdef UA_MULTITHREADING
  43. # ifdef __GNUC__
  44. # define UA_THREAD_LOCAL __thread
  45. # elif defined(_MSC_VER)
  46. # define UA_THREAD_LOCAL __declspec(thread)
  47. # else
  48. # error No thread local storage keyword defined for this compiler
  49. # endif
  50. #else
  51. # define UA_THREAD_LOCAL
  52. #endif
  53. /********************/
  54. /* System Libraries */
  55. /********************/
  56. #include <time.h>
  57. #ifdef _WIN32
  58. # include <winsock2.h> //needed for amalgation
  59. # include <windows.h>
  60. # undef SLIST_ENTRY
  61. #else
  62. # include <sys/time.h>
  63. #endif
  64. /*************************/
  65. /* External Dependencies */
  66. /*************************/
  67. #include "queue.h"
  68. #ifdef UA_MULTITHREADING
  69. # define _LGPL_SOURCE
  70. # include <urcu.h>
  71. # include <urcu/wfcqueue.h>
  72. # include <urcu/uatomic.h>
  73. # include <urcu/rculfhash.h>
  74. #include <urcu/lfstack.h>
  75. #endif
  76. #endif /* UA_UTIL_H_ */