put likely/unlikely in scope (#420)
* put likely/unlikely in scope Signed-off-by: SchrodingerZhu <i@zhuyi.fan> * make clang-format happy Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
This commit is contained in:
committed by
GitHub
parent
cd0311b26f
commit
faa80037bb
@@ -6,8 +6,8 @@
|
||||
# define SNMALLOC_FAST_FAIL() __fastfail(28)
|
||||
# define ALWAYSINLINE __forceinline
|
||||
# define NOINLINE __declspec(noinline)
|
||||
# define likely(x) !!(x)
|
||||
# define unlikely(x) !!(x)
|
||||
# define SNMALLOC_LIKELY(x) !!(x)
|
||||
# define SNMALLOC_UNLIKELY(x) !!(x)
|
||||
# define SNMALLOC_SLOW_PATH NOINLINE
|
||||
# define SNMALLOC_FAST_PATH ALWAYSINLINE
|
||||
/**
|
||||
@@ -26,8 +26,8 @@
|
||||
# define SNMALLOC_UNUSED_FUNCTION
|
||||
#else
|
||||
# define SNMALLOC_FAST_FAIL() __builtin_trap()
|
||||
# define likely(x) __builtin_expect(!!(x), 1)
|
||||
# define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
# define SNMALLOC_LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
# define SNMALLOC_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
# define ALWAYSINLINE __attribute__((always_inline))
|
||||
# define NOINLINE __attribute__((noinline))
|
||||
# define SNMALLOC_SLOW_PATH NOINLINE
|
||||
@@ -152,7 +152,7 @@ inline SNMALLOC_FAST_PATH void check_client_error(const char* const str)
|
||||
inline SNMALLOC_FAST_PATH void
|
||||
check_client_impl(bool test, const char* const str)
|
||||
{
|
||||
if (unlikely(!test))
|
||||
if (SNMALLOC_UNLIKELY(!test))
|
||||
check_client_error(str);
|
||||
}
|
||||
#ifdef SNMALLOC_CHECK_CLIENT
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace snmalloc
|
||||
// If defined should be initially false;
|
||||
SNMALLOC_ASSERT(first == nullptr || *first == false);
|
||||
|
||||
if (unlikely(!initialised.load(std::memory_order_acquire)))
|
||||
if (SNMALLOC_UNLIKELY(!initialised.load(std::memory_order_acquire)))
|
||||
{
|
||||
FlagLock lock(flag);
|
||||
if (!initialised)
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace snmalloc
|
||||
if (stack.load(std::memory_order_relaxed) == nullptr)
|
||||
return nullptr;
|
||||
T* old_head = stack.exchange(nullptr);
|
||||
if (unlikely(old_head == nullptr))
|
||||
if (SNMALLOC_UNLIKELY(old_head == nullptr))
|
||||
return nullptr;
|
||||
|
||||
auto next = old_head->next.load(std::memory_order_relaxed);
|
||||
|
||||
Reference in New Issue
Block a user