Apollo 9.0
自动驾驶开放平台
macros.h 文件参考
#include <cstdlib>
#include <new>
macros.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

宏定义

#define cyber_likely(x)   (x)
 
#define cyber_unlikely(x)   (x)
 
#define CACHELINE_SIZE   64
 
#define DEFINE_TYPE_TRAIT(name, func)
 

函数

void cpu_relax ()
 
void * CheckedMalloc (size_t size)
 
void * CheckedCalloc (size_t num, size_t size)
 

宏定义说明

◆ CACHELINE_SIZE

#define CACHELINE_SIZE   64

在文件 macros.h 第 31 行定义.

◆ cyber_likely

#define cyber_likely (   x)    (x)

在文件 macros.h 第 27 行定义.

◆ cyber_unlikely

#define cyber_unlikely (   x)    (x)

在文件 macros.h 第 28 行定义.

◆ 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()

void cpu_relax ( )
inline

在文件 macros.h 第 51 行定义.

51 {
52#if defined(__aarch64__)
53 asm volatile("yield" ::: "memory");
54#else
55 asm volatile("rep; nop" ::: "memory");
56#endif
57}