ua_util.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef UA_UTIL_H_
  2. #define UA_UTIL_H_
  3. #ifndef UA_AMALGAMATE
  4. # include "ua_config.h"
  5. #endif
  6. #ifndef __USE_POSIX
  7. # define __USE_POSIX
  8. #endif
  9. #ifndef _POSIX_SOURCE
  10. # define _POSIX_SOURCE
  11. #endif
  12. #ifndef _POSIX_C_SOURCE
  13. # define _POSIX_C_SOURCE 199309L
  14. #endif
  15. #ifndef _BSD_SOURCE
  16. # define _BSD_SOURCE
  17. #endif
  18. #ifndef _DEFAULT_SOURCE
  19. # define _DEFAULT_SOURCE
  20. #endif
  21. /*********************/
  22. /* Memory Management */
  23. /*********************/
  24. #include <stdlib.h> // malloc, free
  25. #include <string.h> // memcpy
  26. #include <assert.h> // assert
  27. #ifdef _WIN32
  28. # include <malloc.h>
  29. #endif
  30. /* Visual Studio needs __restrict */
  31. #ifdef _MSC_VER
  32. #define UA_RESTRICT __restrict
  33. #else
  34. #define UA_RESTRICT restrict
  35. #endif
  36. #define UA_NULL ((void *)0)
  37. // subtract from nodeids to get from the encoding to the content
  38. #define UA_ENCODINGOFFSET_XML 1
  39. #define UA_ENCODINGOFFSET_BINARY 2
  40. #define UA_assert(ignore) assert(ignore)
  41. /* Replace the macros with functions for custom allocators if necessary */
  42. #ifndef UA_free
  43. #define UA_free(ptr) free(ptr)
  44. #endif
  45. #ifndef UA_malloc
  46. #define UA_malloc(size) malloc(size)
  47. #endif
  48. #ifndef UA_calloc
  49. #define UA_calloc(num, size) calloc(num, size)
  50. #endif
  51. #ifndef UA_realloc
  52. #define UA_realloc(ptr, size) realloc(ptr, size)
  53. #endif
  54. #define UA_memcpy(dst, src, size) memcpy(dst, src, size)
  55. #define UA_memset(ptr, value, size) memset(ptr, value, size)
  56. #ifdef NO_ALLOCA
  57. #else
  58. #ifdef _WIN32
  59. # define UA_alloca(SIZE) _alloca(SIZE)
  60. #else
  61. #ifdef __GNUC__
  62. # define UA_alloca(size) __builtin_alloca (size)
  63. #else
  64. # include <alloca.h>
  65. # define UA_alloca(SIZE) alloca(SIZE)
  66. #endif
  67. #endif
  68. #endif /* NO_ALLOCA */
  69. /********************/
  70. /* System Libraries */
  71. /********************/
  72. #include <stdarg.h> // va_start, va_end
  73. #include <time.h>
  74. #include <stdio.h> // printf
  75. #include <inttypes.h>
  76. #ifdef _WIN32
  77. # include <winsock2.h> //needed for amalgation
  78. # include <windows.h>
  79. # undef SLIST_ENTRY
  80. # define RAND(SEED) (UA_UInt32)rand()
  81. #else
  82. # include <sys/time.h>
  83. # define RAND(SEED) (UA_UInt32)rand_r(SEED)
  84. # ifndef UA_NON_LITTLEENDIAN_ARCHITECTURE
  85. # if defined(__linux__) || defined(__APPLE__)
  86. # include <endian.h>
  87. # if ( __BYTE_ORDER != __LITTLE_ENDIAN )
  88. # define UA_NON_LITTLEENDIAN_ARCHITECTURE
  89. # endif
  90. # endif
  91. # endif
  92. #endif
  93. /*************************/
  94. /* External Dependencies */
  95. /*************************/
  96. #ifndef UA_AMALGAMATE
  97. # include "queue.h"
  98. #endif
  99. #ifdef UA_MULTITHREADING
  100. # define _LGPL_SOURCE
  101. # include <urcu.h>
  102. # include <urcu/wfcqueue.h>
  103. # include <urcu/uatomic.h>
  104. # include <urcu/rculfhash.h>
  105. #include <urcu/lfstack.h>
  106. #endif
  107. #endif /* UA_UTIL_H_ */