17 #ifndef CYBER_BASE_MACROS_H_ 18 #define CYBER_BASE_MACROS_H_ 24 #define cyber_likely(x) (__builtin_expect((x), 1)) 25 #define cyber_unlikely(x) (__builtin_expect((x), 0)) 27 #define cyber_likely(x) (x) 28 #define cyber_unlikely(x) (x) 31 #define CACHELINE_SIZE 64 33 #define DEFINE_TYPE_TRAIT(name, func) \ 34 template <typename T> \ 36 template <typename Class> \ 37 static constexpr bool Test(decltype(&Class::func)*) { \ 41 static constexpr bool Test(...) { \ 45 static constexpr bool value = Test<T>(nullptr); \ 48 template <typename T> \ 49 constexpr bool name<T>::value; 52 #if defined(__aarch64__) 53 asm volatile(
"yield" :::
"memory");
55 asm volatile(
"rep; nop" :::
"memory");
60 void* ptr = std::malloc(size);
62 throw std::bad_alloc();
68 void* ptr = std::calloc(num, size);
70 throw std::bad_alloc();
75 #endif // CYBER_BASE_MACROS_H_ void cpu_relax()
Definition: macros.h:51
void * CheckedMalloc(size_t size)
Definition: macros.h:59
void * CheckedCalloc(size_t num, size_t size)
Definition: macros.h:67