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:
@@ -58,8 +58,39 @@ namespace snmalloc
|
||||
class MemoryProviderStateMixin : public PAL
|
||||
{
|
||||
std::atomic_flag lock = ATOMIC_FLAG_INIT;
|
||||
void* bump;
|
||||
size_t remaining;
|
||||
void* bump = 0;
|
||||
size_t remaining = 0;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Stack of large allocations that have been returned for reuse.
|
||||
*/
|
||||
ModArray<NUM_LARGE_CLASSES, MPMCStack<Largeslab, RequiresInit>> large_stack;
|
||||
|
||||
static MemoryProviderStateMixin<PAL>* make() noexcept
|
||||
{
|
||||
// Temporary storage to start the allocator in.
|
||||
MemoryProviderStateMixin<PAL> local;
|
||||
|
||||
// Allocate permanent storage for the allocator usung temporary allocator
|
||||
MemoryProviderStateMixin<PAL>* allocated
|
||||
= local.alloc_chunk<MemoryProviderStateMixin<PAL>, 1>();
|
||||
|
||||
// Put temporary allocator we have used, into the permanent storage.
|
||||
// memcpy is safe as this is entirely single threaded.
|
||||
memcpy(allocated, &local, sizeof(MemoryProviderStateMixin<PAL>));
|
||||
|
||||
return allocated;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The last time we saw a low memory notification.
|
||||
*/
|
||||
std::atomic<uint64_t> last_low_memory_epoch = 0;
|
||||
std::atomic_flag lazy_decommit_guard = {};
|
||||
|
||||
|
||||
void new_block()
|
||||
{
|
||||
@@ -71,11 +102,6 @@ namespace snmalloc
|
||||
remaining = SUPERSLAB_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* The last time we saw a low memory notification.
|
||||
*/
|
||||
std::atomic<uint64_t> last_low_memory_epoch = 0;
|
||||
std::atomic_flag lazy_decommit_guard;
|
||||
SNMALLOC_SLOW_PATH void lazy_decommit()
|
||||
{
|
||||
// If another thread is try to do lazy decommit, let it continue. If
|
||||
@@ -141,11 +167,6 @@ namespace snmalloc
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Stack of large allocations that have been returned for reuse.
|
||||
*/
|
||||
ModArray<NUM_LARGE_CLASSES, MPMCStack<Largeslab, PreZeroed>> large_stack;
|
||||
|
||||
/**
|
||||
* Primitive allocator for structure that are required before
|
||||
* the allocator can be running.
|
||||
@@ -422,5 +443,8 @@ namespace snmalloc
|
||||
* The memory provider that will be used if no other provider is explicitly
|
||||
* passed as an argument.
|
||||
*/
|
||||
inline GlobalVirtual default_memory_provider;
|
||||
inline GlobalVirtual& default_memory_provider()
|
||||
{
|
||||
return *(Singleton<GlobalVirtual*, GlobalVirtual::make>::get());
|
||||
}
|
||||
} // namespace snmalloc
|
||||
|
||||
Reference in New Issue
Block a user