Clang format.

This commit is contained in:
Matthew Parkinson
2020-02-26 20:59:38 +00:00
parent 136dd23932
commit c1c8a7bfee
3 changed files with 26 additions and 28 deletions

View File

@@ -58,7 +58,7 @@ namespace snmalloc
class MemoryProviderStateMixin : public PAL class MemoryProviderStateMixin : public PAL
{ {
std::atomic_flag lock = ATOMIC_FLAG_INIT; std::atomic_flag lock = ATOMIC_FLAG_INIT;
void* bump = 0; void* bump = nullptr;
size_t remaining = 0; size_t remaining = 0;
public: public:
@@ -67,31 +67,29 @@ namespace snmalloc
*/ */
ModArray<NUM_LARGE_CLASSES, MPMCStack<Largeslab, RequiresInit>> large_stack; ModArray<NUM_LARGE_CLASSES, MPMCStack<Largeslab, RequiresInit>> large_stack;
static MemoryProviderStateMixin<PAL>* make() noexcept static MemoryProviderStateMixin<PAL>* make() noexcept
{ {
// Temporary storage to start the allocator in. // Temporary storage to start the allocator in.
MemoryProviderStateMixin<PAL> local; MemoryProviderStateMixin<PAL> local;
// Allocate permanent storage for the allocator usung temporary allocator // Allocate permanent storage for the allocator usung temporary allocator
MemoryProviderStateMixin<PAL>* allocated MemoryProviderStateMixin<PAL>* allocated =
= local.alloc_chunk<MemoryProviderStateMixin<PAL>, 1>(); local.alloc_chunk<MemoryProviderStateMixin<PAL>, 1>();
// Put temporary allocator we have used, into the permanent storage. // Put temporary allocator we have used, into the permanent storage.
// memcpy is safe as this is entirely single threaded. // memcpy is safe as this is entirely single threaded.
memcpy(allocated, &local, sizeof(MemoryProviderStateMixin<PAL>)); memcpy(allocated, &local, sizeof(MemoryProviderStateMixin<PAL>));
return allocated; return allocated;
} }
private: private:
/** /**
* The last time we saw a low memory notification. * The last time we saw a low memory notification.
*/ */
std::atomic<uint64_t> last_low_memory_epoch = 0; std::atomic<uint64_t> last_low_memory_epoch = 0;
std::atomic_flag lazy_decommit_guard = {}; std::atomic_flag lazy_decommit_guard = {};
void new_block() void new_block()
{ {
// Reserve the smallest large_class which is SUPERSLAB_SIZE // Reserve the smallest large_class which is SUPERSLAB_SIZE

View File

@@ -87,12 +87,12 @@ namespace snmalloc
**/ **/
static void register_cleanup() static void register_cleanup()
{ {
#ifdef USE_SNMALLOC_STATS # ifdef USE_SNMALLOC_STATS
Singleton<int, atexit_print_stats>::get(); Singleton<int, atexit_print_stats>::get();
#endif # endif
} }
#ifdef USE_SNMALLOC_STATS # ifdef USE_SNMALLOC_STATS
static void print_stats() static void print_stats()
{ {
Stats s; Stats s;
@@ -104,7 +104,7 @@ namespace snmalloc
{ {
return atexit(print_stats); return atexit(print_stats);
} }
#endif # endif
public: public:
/** /**
@@ -143,15 +143,15 @@ namespace snmalloc
*/ */
static SNMALLOC_FAST_PATH Alloc* get() static SNMALLOC_FAST_PATH Alloc* get()
{ {
#ifdef USE_MALLOC # ifdef USE_MALLOC
return get_reference(); return get_reference();
#else # else
auto alloc = get_reference(); auto alloc = get_reference();
auto new_alloc = lazy_replacement(alloc); auto new_alloc = lazy_replacement(alloc);
return (likely(new_alloc == nullptr)) ? return (likely(new_alloc == nullptr)) ?
alloc : alloc :
reinterpret_cast<Alloc*>(new_alloc); reinterpret_cast<Alloc*>(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 * Entry point that allows libc to call into the allocator for per-thread
* cleanup. * cleanup.
@@ -210,9 +210,9 @@ namespace snmalloc
ThreadAllocLibcCleanup::inner_release(); ThreadAllocLibcCleanup::inner_release();
} }
using ThreadAlloc = ThreadAllocLibcCleanup; using ThreadAlloc = ThreadAllocLibcCleanup;
#else # else
using ThreadAlloc = ThreadAllocThreadDestructor; using ThreadAlloc = ThreadAllocThreadDestructor;
#endif # endif
/** /**
* Slow path for the placeholder replacement. The simple check that this is * Slow path for the placeholder replacement. The simple check that this is

View File

@@ -14,7 +14,7 @@ public:
{ {
return alloc; return alloc;
} }
alloc = current_alloc_pool()->acquire(); alloc = current_alloc_pool()->acquire();
return alloc; return alloc;
} }
@@ -31,13 +31,13 @@ int main()
// 28 is large enough to produce a nested allocator. // 28 is large enough to produce a nested allocator.
// It is also large enough for the example to run in. // It is also large enough for the example to run in.
// For 1MiB superslabs, SUPERSLAB_BITS + 4 is not big enough for the example. // For 1MiB superslabs, SUPERSLAB_BITS + 4 is not big enough for the example.
auto a = ThreadAlloc::get(); auto a = ThreadAlloc::get();
for (size_t i = 0; i < 1000; i++) for (size_t i = 0; i < 1000; i++)
{ {
auto r1 = a->alloc(100); auto r1 = a->alloc(100);
a->dealloc(r1); a->dealloc(r1);
} }
} }