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
{
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<NUM_LARGE_CLASSES, MPMCStack<Largeslab, RequiresInit>> large_stack;
static MemoryProviderStateMixin<PAL>* make() noexcept
{
// Temporary storage to start the allocator in.
MemoryProviderStateMixin<PAL> local;
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>();
// 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>));
// 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;
}
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()
{
// Reserve the smallest large_class which is SUPERSLAB_SIZE

View File

@@ -87,12 +87,12 @@ namespace snmalloc
**/
static void register_cleanup()
{
#ifdef USE_SNMALLOC_STATS
# ifdef USE_SNMALLOC_STATS
Singleton<int, atexit_print_stats>::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<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
* 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

View File

@@ -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);
}
}