68 lines
1.4 KiB
C
Raw Normal View History

2018-05-24 17:17:37 +02:00
#ifndef JEMALLOC_INTERNAL_UTIL_H
#define JEMALLOC_INTERNAL_UTIL_H
2018-05-24 17:17:37 +02:00
#define UTIL_INLINE static inline
2015-10-06 16:18:30 +02:00
2018-05-24 17:17:37 +02:00
/* Junk fill patterns. */
#ifndef JEMALLOC_ALLOC_JUNK
# define JEMALLOC_ALLOC_JUNK ((uint8_t)0xa5)
#endif
#ifndef JEMALLOC_FREE_JUNK
# define JEMALLOC_FREE_JUNK ((uint8_t)0x5a)
#endif
/*
* Wrap a cpp argument that contains commas such that it isn't broken up into
* multiple arguments.
*/
2018-05-24 17:17:37 +02:00
#define JEMALLOC_ARG_CONCAT(...) __VA_ARGS__
/* cpp macro definition stringification. */
#define STRINGIFY_HELPER(x) #x
#define STRINGIFY(x) STRINGIFY_HELPER(x)
/*
* Silence compiler warnings due to uninitialized values. This is used
* wherever the compiler fails to recognize that the variable is never used
* uninitialized.
*/
2018-05-24 17:17:37 +02:00
#define JEMALLOC_CC_SILENCE_INIT(v) = v
2015-10-06 16:18:30 +02:00
#ifdef __GNUC__
2018-05-24 17:17:37 +02:00
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
2015-10-06 16:18:30 +02:00
#else
2018-05-24 17:17:37 +02:00
# define likely(x) !!(x)
# define unlikely(x) !!(x)
2015-10-06 16:18:30 +02:00
#endif
2018-05-24 17:17:37 +02:00
#if !defined(JEMALLOC_INTERNAL_UNREACHABLE)
# error JEMALLOC_INTERNAL_UNREACHABLE should have been defined by configure
2015-10-06 16:18:30 +02:00
#endif
2018-05-24 17:17:37 +02:00
#define unreachable() JEMALLOC_INTERNAL_UNREACHABLE()
2015-10-06 16:18:30 +02:00
/* Set error code. */
2018-05-24 17:17:37 +02:00
UTIL_INLINE void
set_errno(int errnum) {
#ifdef _WIN32
SetLastError(errnum);
#else
errno = errnum;
#endif
}
2015-10-06 16:18:30 +02:00
/* Get last error code. */
2018-05-24 17:17:37 +02:00
UTIL_INLINE int
get_errno(void) {
#ifdef _WIN32
2018-05-24 17:17:37 +02:00
return GetLastError();
#else
2018-05-24 17:17:37 +02:00
return errno;
#endif
}
2018-05-24 17:17:37 +02:00
#undef UTIL_INLINE
#endif /* JEMALLOC_INTERNAL_UTIL_H */