replace assert with SNMALLOC_ASSERT
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "../pal/pal_consts.h"
|
||||
#include "bits.h"
|
||||
|
||||
#include <cassert>
|
||||
@@ -95,8 +96,8 @@ namespace snmalloc
|
||||
template<typename T = void>
|
||||
inline T* pointer_align_up(void* p, size_t alignment)
|
||||
{
|
||||
assert(alignment > 0);
|
||||
assert(bits::next_pow2(alignment) == alignment);
|
||||
SNMALLOC_ASSERT(alignment > 0);
|
||||
SNMALLOC_ASSERT(bits::next_pow2(alignment) == alignment);
|
||||
#if __has_builtin(__builtin_align_up)
|
||||
return static_cast<T*>(__builtin_align_up(p, alignment));
|
||||
#else
|
||||
@@ -111,7 +112,7 @@ namespace snmalloc
|
||||
*/
|
||||
inline size_t pointer_diff(void* base, void* cursor)
|
||||
{
|
||||
assert(cursor >= base);
|
||||
SNMALLOC_ASSERT(cursor >= base);
|
||||
return static_cast<size_t>(
|
||||
static_cast<char*>(cursor) - static_cast<char*>(base));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// #define USE_LZCNT
|
||||
|
||||
#include "../aal/aal.h"
|
||||
#include "../pal/pal_consts.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include <atomic>
|
||||
@@ -225,7 +226,7 @@ namespace snmalloc
|
||||
|
||||
static SNMALLOC_FAST_PATH size_t align_down(size_t value, size_t alignment)
|
||||
{
|
||||
assert(next_pow2(alignment) == alignment);
|
||||
SNMALLOC_ASSERT(next_pow2(alignment) == alignment);
|
||||
|
||||
size_t align_1 = alignment - 1;
|
||||
value &= ~align_1;
|
||||
@@ -234,7 +235,7 @@ namespace snmalloc
|
||||
|
||||
static inline size_t align_up(size_t value, size_t alignment)
|
||||
{
|
||||
assert(next_pow2(alignment) == alignment);
|
||||
SNMALLOC_ASSERT(next_pow2(alignment) == alignment);
|
||||
|
||||
size_t align_1 = alignment - 1;
|
||||
value += align_1;
|
||||
|
||||
@@ -30,8 +30,25 @@
|
||||
|
||||
#define UNUSED(x) ((void)(x))
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
void error(const char* const str);
|
||||
} // namespace snmalloc
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define SNMALLOC_ASSERT(expr) ((void 0))
|
||||
#else
|
||||
# define SNMALLOC_ASSERT(expr) \
|
||||
{ \
|
||||
if (!(expr)) \
|
||||
{ \
|
||||
snmalloc::error("assert fail"); \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
# define SNMALLOC_ASSUME(x) assert(x)
|
||||
# define SNMALLOC_ASSUME(x) SNMALLOC_ASSERT(x)
|
||||
#else
|
||||
# if __has_builtin(__builtin_assume)
|
||||
# define SNMALLOC_ASSUME(x) __builtin_assume((x))
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace snmalloc
|
||||
|
||||
while (curr != item)
|
||||
{
|
||||
assert(curr != Terminator());
|
||||
SNMALLOC_ASSERT(curr != Terminator());
|
||||
curr = curr->next;
|
||||
}
|
||||
#else
|
||||
@@ -171,7 +171,7 @@ namespace snmalloc
|
||||
|
||||
while (curr != Terminator())
|
||||
{
|
||||
assert(curr != item);
|
||||
SNMALLOC_ASSERT(curr != item);
|
||||
curr = curr->next;
|
||||
}
|
||||
#else
|
||||
@@ -187,7 +187,7 @@ namespace snmalloc
|
||||
|
||||
while (item != Terminator())
|
||||
{
|
||||
assert(item->prev == prev);
|
||||
SNMALLOC_ASSERT(item->prev == prev);
|
||||
prev = item;
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace snmalloc
|
||||
static Object obj;
|
||||
|
||||
// If defined should be initially false;
|
||||
assert(first == nullptr || *first == false);
|
||||
SNMALLOC_ASSERT(first == nullptr || *first == false);
|
||||
|
||||
if (unlikely(!initialised.load(std::memory_order_acquire)))
|
||||
{
|
||||
|
||||
@@ -20,10 +20,8 @@ namespace snmalloc
|
||||
public:
|
||||
void invariant()
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
assert(back != nullptr);
|
||||
assert(front != nullptr);
|
||||
#endif
|
||||
SNMALLOC_ASSERT(back != nullptr);
|
||||
SNMALLOC_ASSERT(front != nullptr);
|
||||
}
|
||||
|
||||
void init(T* stub)
|
||||
@@ -71,7 +69,7 @@ namespace snmalloc
|
||||
{
|
||||
front = next;
|
||||
Aal::prefetch(&(next->next));
|
||||
assert(front);
|
||||
SNMALLOC_ASSERT(front);
|
||||
std::atomic_thread_fence(std::memory_order_acquire);
|
||||
invariant();
|
||||
return std::pair(first, true);
|
||||
|
||||
Reference in New Issue
Block a user