#include <cstdlib>
#include <new>
浏览源代码.
◆ CACHELINE_SIZE
| #define CACHELINE_SIZE 64 |
◆ cyber_likely
| #define cyber_likely |
( |
|
x | ) |
(x) |
◆ cyber_unlikely
| #define cyber_unlikely |
( |
|
x | ) |
(x) |
◆ DEFINE_TYPE_TRAIT
| #define DEFINE_TYPE_TRAIT |
( |
|
name, |
|
|
|
func |
|
) |
| |
值: template <typename T> \
struct name { \
template <typename Class> \
static constexpr bool Test(decltype(&Class::func)*) { \
return true; \
} \
template <typename> \
static constexpr bool Test(...) { \
return false; \
} \
\
static constexpr bool value = Test<T>(nullptr); \
}; \
\
template <typename T> \
constexpr bool name<T>::value;
在文件 macros.h 第 33 行定义.
35 { \
36 template <typename Class> \
37 static constexpr bool Test(decltype(&Class::func)*) { \
38 return true; \
39 } \
40 template <typename> \
41 static constexpr bool Test(...) { \
42 return false; \
43 } \
44 \
45 static constexpr bool value = Test<T>(nullptr); \
46 }; \
47 \
48 template <typename T> \
49 constexpr bool name<T>::value;
◆ CheckedCalloc()
| void * CheckedCalloc |
( |
size_t |
num, |
|
|
size_t |
size |
|
) |
| |
|
inline |
在文件 macros.h 第 67 行定义.
67 {
68 void* ptr = std::calloc(num, size);
69 if (!ptr) {
70 throw std::bad_alloc();
71 }
72 return ptr;
73}
◆ CheckedMalloc()
| void * CheckedMalloc |
( |
size_t |
size | ) |
|
|
inline |
在文件 macros.h 第 59 行定义.
59 {
60 void* ptr = std::malloc(size);
61 if (!ptr) {
62 throw std::bad_alloc();
63 }
64 return ptr;
65}
◆ cpu_relax()
在文件 macros.h 第 51 行定义.
51 {
52#if defined(__aarch64__)
53 asm volatile("yield" ::: "memory");
54#else
55 asm volatile("rep; nop" ::: "memory");
56#endif
57}