Reduce dependence on C++ runtime
If the external thread statics are used, then we don't need to include some C++ runtime concepts. This refactoring moves some global initialization under conditional compilation.
This commit is contained in:
@@ -19,6 +19,8 @@ extern "C" const void* __oe_get_heap_end()
|
||||
|
||||
extern "C" void* oe_memset(void* p, int c, size_t size)
|
||||
{
|
||||
std::cout << "Memset " << p << " - " << size << std::endl;
|
||||
|
||||
return memset(p, c, size);
|
||||
}
|
||||
|
||||
@@ -30,7 +32,7 @@ extern "C" void oe_abort()
|
||||
using namespace snmalloc;
|
||||
int main()
|
||||
{
|
||||
MemoryProviderStateMixin<DefaultPal> mp;
|
||||
auto& mp = *MemoryProviderStateMixin<DefaultPal>::make();
|
||||
|
||||
// 28 is large enough to produce a nested allocator.
|
||||
// It is also large enough for the example to run in.
|
||||
|
||||
40
src/test/func/thread_alloc_external/thread_alloc_external.cc
Normal file
40
src/test/func/thread_alloc_external/thread_alloc_external.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
#define SNMALLOC_EXTERNAL_THREAD_ALLOC
|
||||
#include <mem/globalalloc.h>
|
||||
using namespace snmalloc;
|
||||
|
||||
class ThreadAllocUntyped
|
||||
{
|
||||
public:
|
||||
static void* get()
|
||||
{
|
||||
static thread_local void* alloc = nullptr;
|
||||
if (alloc != nullptr)
|
||||
{
|
||||
return alloc;
|
||||
}
|
||||
|
||||
alloc = current_alloc_pool()->acquire();
|
||||
return alloc;
|
||||
}
|
||||
};
|
||||
|
||||
#include <override/malloc.cc>
|
||||
|
||||
int main()
|
||||
{
|
||||
MemoryProviderStateMixin<DefaultPal> mp;
|
||||
|
||||
// 28 is large enough to produce a nested allocator.
|
||||
// It is also large enough for the example to run in.
|
||||
// For 1MiB superslabs, SUPERSLAB_BITS + 4 is not big enough for the example.
|
||||
|
||||
auto a = ThreadAlloc::get();
|
||||
|
||||
for (size_t i = 0; i < 1000; i++)
|
||||
{
|
||||
auto r1 = a->alloc(100);
|
||||
|
||||
free(r1);
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ bool has_pressure()
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t current_epoch = default_memory_provider.low_memory_epoch();
|
||||
uint64_t current_epoch = default_memory_provider().low_memory_epoch();
|
||||
bool result = epoch != current_epoch;
|
||||
epoch = current_epoch;
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user