29 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
31 #if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_ARCH_PPC64) || defined(__s390x__) || \
32 (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8)
42 #define XRT_PRINTF_FORMAT(fmt, list) __attribute__((format(printf, fmt, list)))
44 #define XRT_PRINTF_FORMAT(fmt, list)
52 #define XRT_MAYBE_UNUSED __attribute__((unused))
53 #elif defined(_MSC_VER) && defined(__cplusplus)
54 #define XRT_MAYBE_UNUSED [[maybe_unused]]
56 #define XRT_MAYBE_UNUSED
63 #if defined(__GNUC__) && (__GNUC__ >= 4)
64 #define XRT_CHECK_RESULT __attribute__((warn_unused_result))
65 #elif defined(_MSC_VER) && (_MSC_VER >= 1700)
66 #define XRT_CHECK_RESULT _Check_return_
68 #define XRT_CHECK_RESULT
76 #define XRT_NO_INLINE __attribute__((noinline))
77 #elif defined(_MSC_VER)
78 #define XRT_NO_INLINE __declspec(noinline)
90 #define XRT_DEBUGBREAK()
91 #elif defined(__clang__) || defined(__GNUC__)
92 #define XRT_DEBUGBREAK() __builtin_trap()
93 #elif defined(_MSC_VER)
94 #define XRT_DEBUGBREAK() __debugbreak()
96 #error "compiler not supported"
101 typedef volatile int32_t xrt_atomic_s32_t;
103 static inline int32_t
104 xrt_atomic_s32_inc_return(xrt_atomic_s32_t *p)
106 #if defined(__GNUC__)
107 return __sync_add_and_fetch(p, 1);
108 #elif defined(_MSC_VER)
109 return InterlockedIncrement((
volatile LONG *)p);
111 #error "compiler not supported"
114 static inline int32_t
115 xrt_atomic_s32_dec_return(xrt_atomic_s32_t *p)
117 #if defined(__GNUC__)
118 return __sync_sub_and_fetch(p, 1);
119 #elif defined(_MSC_VER)
120 return InterlockedDecrement((
volatile LONG *)p);
122 #error "compiler not supported"
125 static inline int32_t
126 xrt_atomic_s32_cmpxchg(xrt_atomic_s32_t *p, int32_t old_, int32_t new_)
128 #if defined(__GNUC__)
129 return __sync_val_compare_and_swap(p, old_, new_);
130 #elif defined(_MSC_VER)
131 return InterlockedCompareExchange((
volatile LONG *)p, old_, new_);
133 #error "compiler not supported"
138 typedef intptr_t ssize_t;
140 #define _SSIZE_T_DEFINED
148 #define container_of(ptr, type, field) (type *)((char *)ptr - offsetof(type, field))
161 #define XRT_STRUCT_INIT {}
164 #elif defined(__cplusplus)
167 #define XRT_STRUCT_INIT {}
173 #define XRT_STRUCT_INIT {0}
A minimal way to include Windows.h.