ua_util.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef UA_UTIL_H_
  2. #define UA_UTIL_H_
  3. #include "ua_config.h"
  4. /*********************/
  5. /* Memory Management */
  6. /*********************/
  7. #include <stdlib.h> // malloc, free
  8. #include <string.h> // memcpy
  9. #include <assert.h> // assert
  10. #ifdef _WIN32
  11. # include <malloc.h>
  12. #endif
  13. /* Visual Studio needs __restrict */
  14. #ifdef _MSC_VER
  15. # define UA_RESTRICT __restrict
  16. #else
  17. # define UA_RESTRICT restrict
  18. #endif
  19. /* Visual Studio does not know fnct/unistd file access results */
  20. #ifdef _MSC_VER
  21. #ifndef R_OK
  22. #define R_OK 4 /* Test for read permission. */
  23. #endif
  24. #ifndef R_OK
  25. #define W_OK 2 /* Test for write permission. */
  26. #endif
  27. #ifndef X_OK
  28. #define X_OK 1 /* Test for execute permission. */
  29. #endif
  30. #ifndef F_OK
  31. #define F_OK 0 /* Test for existence. */
  32. #endif
  33. #endif
  34. #define UA_NULL ((void *)0)
  35. // subtract from nodeids to get from the encoding to the content
  36. #define UA_ENCODINGOFFSET_XML 1
  37. #define UA_ENCODINGOFFSET_BINARY 2
  38. #define UA_assert(ignore) assert(ignore)
  39. /* Replace the macros with functions for custom allocators if necessary */
  40. #ifndef UA_free
  41. # define UA_free(ptr) free(ptr)
  42. #endif
  43. #ifndef UA_malloc
  44. # define UA_malloc(size) malloc(size)
  45. #endif
  46. #ifndef UA_calloc
  47. # define UA_calloc(num, size) calloc(num, size)
  48. #endif
  49. #ifndef UA_realloc
  50. # define UA_realloc(ptr, size) realloc(ptr, size)
  51. #endif
  52. #define UA_memcpy(dst, src, size) memcpy(dst, src, size)
  53. #define UA_memset(ptr, value, size) memset(ptr, value, size)
  54. #ifndef NO_ALLOCA
  55. # ifdef __GNUC__
  56. # define UA_alloca(size) __builtin_alloca (size)
  57. # elif defined(_WIN32)
  58. # define UA_alloca(SIZE) _alloca(SIZE)
  59. # else
  60. # include <alloca.h>
  61. # define UA_alloca(SIZE) alloca(SIZE)
  62. # endif
  63. #endif
  64. /************************/
  65. /* Thread Local Storage */
  66. /************************/
  67. #ifdef UA_MULTITHREADING
  68. # ifdef __GNUC__
  69. # define UA_THREAD_LOCAL __thread
  70. # elif defined(_MSC_VER)
  71. # define UA_THREAD_LOCAL __declspec(thread)
  72. # else
  73. # error No thread local storage keyword defined for this compiler
  74. # endif
  75. #else
  76. # define UA_THREAD_LOCAL
  77. #endif
  78. /********************/
  79. /* System Libraries */
  80. /********************/
  81. #include <stdarg.h> // va_start, va_end
  82. #include <time.h>
  83. #include <stdio.h> // printf
  84. #ifdef _WIN32
  85. # include <winsock2.h> //needed for amalgation
  86. # include <windows.h>
  87. # undef SLIST_ENTRY
  88. #else
  89. # include <sys/time.h>
  90. #endif
  91. /*************************/
  92. /* External Dependencies */
  93. /*************************/
  94. #include "queue.h"
  95. #ifdef UA_MULTITHREADING
  96. # define _LGPL_SOURCE
  97. # include <urcu.h>
  98. # include <urcu/wfcqueue.h>
  99. # include <urcu/uatomic.h>
  100. # include <urcu/rculfhash.h>
  101. #include <urcu/lfstack.h>
  102. #endif
  103. #endif /* UA_UTIL_H_ */