1#ifndef JEMALLOC_INTERNAL_UTIL_H 2#define JEMALLOC_INTERNAL_UTIL_H 3 4#define UTIL_INLINE static inline 5 6/* Junk fill patterns. */ 7#ifndef JEMALLOC_ALLOC_JUNK 8# define JEMALLOC_ALLOC_JUNK ((uint8_t)0xa5) 9#endif 10#ifndef JEMALLOC_FREE_JUNK 11# define JEMALLOC_FREE_JUNK ((uint8_t)0x5a) 12#endif 13 14/* 15 * Wrap a cpp argument that contains commas such that it isn't broken up into 16 * multiple arguments. 17 */ 18#define JEMALLOC_ARG_CONCAT(...) __VA_ARGS__ 19 20/* cpp macro definition stringification. */ 21#define STRINGIFY_HELPER(x) #x 22#define STRINGIFY(x) STRINGIFY_HELPER(x) 23 24/* 25 * Silence compiler warnings due to uninitialized values. This is used 26 * wherever the compiler fails to recognize that the variable is never used 27 * uninitialized. 28 */ 29#define JEMALLOC_CC_SILENCE_INIT(v) = v 30 31#ifdef __GNUC__ 32# define likely(x) __builtin_expect(!!(x), 1) 33# define unlikely(x) __builtin_expect(!!(x), 0) 34#else 35# define likely(x) !!(x) 36# define unlikely(x) !!(x) 37#endif 38 39#if !defined(JEMALLOC_INTERNAL_UNREACHABLE) 40# error JEMALLOC_INTERNAL_UNREACHABLE should have been defined by configure 41#endif 42 43#define unreachable() JEMALLOC_INTERNAL_UNREACHABLE() 44 45/* Set error code. */ 46UTIL_INLINE void 47set_errno(int errnum) { 48#ifdef _WIN32 49 SetLastError(errnum); 50#else 51 errno = errnum; 52#endif 53} 54 55/* Get last error code. */ 56UTIL_INLINE int 57get_errno(void) { 58#ifdef _WIN32 59 return GetLastError(); 60#else 61 return errno; 62#endif 63} 64 65#undef UTIL_INLINE 66 67#endif /* JEMALLOC_INTERNAL_UTIL_H */ 68