diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index b3cca67..7e3de6a 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -58,7 +58,7 @@ namespace snmalloc class MemoryProviderStateMixin : public PAL { std::atomic_flag lock = ATOMIC_FLAG_INIT; - void* bump = 0; + void* bump = nullptr; size_t remaining = 0; public: @@ -67,31 +67,29 @@ namespace snmalloc */ ModArray> large_stack; - static MemoryProviderStateMixin* make() noexcept - { - // Temporary storage to start the allocator in. - MemoryProviderStateMixin local; + static MemoryProviderStateMixin* make() noexcept + { + // Temporary storage to start the allocator in. + MemoryProviderStateMixin local; - // Allocate permanent storage for the allocator usung temporary allocator - MemoryProviderStateMixin* allocated - = local.alloc_chunk, 1>(); + // Allocate permanent storage for the allocator usung temporary allocator + MemoryProviderStateMixin* allocated = + local.alloc_chunk, 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)); + // Put temporary allocator we have used, into the permanent storage. + // memcpy is safe as this is entirely single threaded. + memcpy(allocated, &local, sizeof(MemoryProviderStateMixin)); - return allocated; - } + return allocated; + } private: - /** * The last time we saw a low memory notification. */ std::atomic last_low_memory_epoch = 0; std::atomic_flag lazy_decommit_guard = {}; - void new_block() { // Reserve the smallest large_class which is SUPERSLAB_SIZE diff --git a/src/mem/threadalloc.h b/src/mem/threadalloc.h index ee3ff5a..d71bcd2 100644 --- a/src/mem/threadalloc.h +++ b/src/mem/threadalloc.h @@ -87,12 +87,12 @@ namespace snmalloc **/ static void register_cleanup() { -#ifdef USE_SNMALLOC_STATS +# ifdef USE_SNMALLOC_STATS Singleton::get(); -#endif +# endif } -#ifdef USE_SNMALLOC_STATS +# ifdef USE_SNMALLOC_STATS static void print_stats() { Stats s; @@ -104,7 +104,7 @@ namespace snmalloc { return atexit(print_stats); } -#endif +# endif public: /** @@ -143,15 +143,15 @@ namespace snmalloc */ static SNMALLOC_FAST_PATH Alloc* get() { -#ifdef USE_MALLOC +# ifdef USE_MALLOC return get_reference(); -#else +# else auto alloc = get_reference(); auto new_alloc = lazy_replacement(alloc); return (likely(new_alloc == nullptr)) ? alloc : reinterpret_cast(new_alloc); -#endif +# endif } }; @@ -200,7 +200,7 @@ namespace snmalloc } }; -#ifdef SNMALLOC_USE_THREAD_CLEANUP +# ifdef SNMALLOC_USE_THREAD_CLEANUP /** * Entry point that allows libc to call into the allocator for per-thread * cleanup. @@ -210,9 +210,9 @@ namespace snmalloc ThreadAllocLibcCleanup::inner_release(); } using ThreadAlloc = ThreadAllocLibcCleanup; -#else +# else using ThreadAlloc = ThreadAllocThreadDestructor; -#endif +# endif /** * Slow path for the placeholder replacement. The simple check that this is diff --git a/src/test/func/thread_alloc_external/thread_alloc_external.cc b/src/test/func/thread_alloc_external/thread_alloc_external.cc index bfc2b2f..5439248 100644 --- a/src/test/func/thread_alloc_external/thread_alloc_external.cc +++ b/src/test/func/thread_alloc_external/thread_alloc_external.cc @@ -14,7 +14,7 @@ public: { return alloc; } - + alloc = current_alloc_pool()->acquire(); return alloc; } @@ -31,13 +31,13 @@ int main() // 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); - + a->dealloc(r1); } }