Use fewer header files

Removing some includes to reduce the code that is dragged in.
This commit is contained in:
Matthew Parkinson
2019-04-15 16:19:50 +01:00
committed by Matthew Parkinson
parent 30ad9722a7
commit 4faf9f3bee
13 changed files with 39 additions and 25 deletions

View File

@@ -452,5 +452,17 @@ namespace snmalloc
return (size_t)1 << (m_e + LOW_BITS);
}
}
template <typename T>
constexpr inline T min(T t1, T t2)
{
return t1 < t2 ? t1 : t2;
}
template <typename T>
constexpr inline T max(T t1, T t2)
{
return t1 > t2 ? t1 : t2;
}
}
}

View File

@@ -1,9 +1,7 @@
#pragma once
#include "bits.h"
#include <stdlib.h>
#include <utility>
#include "helpers.h"
namespace snmalloc
{

View File

@@ -21,8 +21,6 @@
#include "sizeclasstable.h"
#include "slab.h"
#include <array>
namespace snmalloc
{
enum Boundary

View File

@@ -49,6 +49,7 @@ namespace snmalloc
}
}
#ifdef USE_SNMALLOC_STATS
void print_all_stats(std::ostream& o, uint64_t dumpid = 0)
{
auto alloc = Parent::iterate();
@@ -59,6 +60,12 @@ namespace snmalloc
alloc = Parent::iterate(alloc);
}
}
#else
void print_all_stats(void*& o, uint64_t dumpid = 0)
{
UNUSED(o); UNUSED(dumpid);
}
#endif
void cleanup_unused()
{

View File

@@ -8,8 +8,6 @@
#include "baseslab.h"
#include "sizeclass.h"
#include <utility>
namespace snmalloc
{
template<class PAL>
@@ -61,7 +59,7 @@ namespace snmalloc
size_t bump;
size_t remaining;
std::pair<void*, size_t> reserve_block() noexcept
void new_block()
{
size_t size = SUPERSLAB_SIZE;
void* r = reserve<false>(&size, SUPERSLAB_SIZE);
@@ -70,14 +68,9 @@ namespace snmalloc
error("out of memory");
((PAL*)this)->template notify_using<NoZero>(r, OS_PAGE_SIZE);
return std::make_pair(r, size);
}
void new_block()
{
auto r_size = reserve_block();
bump = (size_t)r_size.first;
remaining = r_size.second;
bump = (size_t)r;
remaining = size;
}
/**

View File

@@ -1,9 +1,10 @@
#pragma once
#include "../ds/bits.h"
#include "../ds/helpers.h"
#include <algorithm>
#include <atomic>
#include <utility>
namespace snmalloc
{
@@ -274,7 +275,7 @@ namespace snmalloc
auto leaf_ix = get_leaf_index<true>(p, success);
size_t ix = leaf_ix.second;
auto last = std::min(LEAF_MASK + 1, ix + length);
auto last = bits::min(LEAF_MASK + 1, ix + length);
auto diff = last - ix;

View File

@@ -30,7 +30,7 @@ namespace snmalloc
bits::from_exp_mant<INTERMEDIATE_BITS, MIN_ALLOC_BITS>(sizeclass);
size_t alignment =
std::min((size_t)1 << bits::ctz_const(size[sizeclass]), OS_PAGE_SIZE);
bits::min((size_t)1 << bits::ctz_const(size[sizeclass]), OS_PAGE_SIZE);
cache_friendly_mask[sizeclass] = (alignment - 1);
inverse_cache_friendly_mask[sizeclass] = ~(alignment - 1);
}

View File

@@ -3,8 +3,7 @@
#include "../ds/helpers.h"
#include "allocslab.h"
#include "metaslab.h"
#include <cstring>
#include <new>
namespace snmalloc
{

View File

@@ -7,6 +7,10 @@
#error At most one out of SNMALLOC_USE_THREAD_CLEANUP and SNMALLOC_USE_THREAD_DESTRUCTOR may be defined.
#endif
#if !defined(_WIN32) && !defined(FreeBSD_KERNEL)
# include "pthread.h"
#endif
namespace snmalloc
{
extern "C" void _malloc_thread_cleanup(void);

View File

@@ -2,6 +2,7 @@
#include "../snmalloc.h"
#include <errno.h>
#include <string.h>
using namespace snmalloc;
@@ -89,7 +90,7 @@ extern "C"
if (p != nullptr)
{
assert(p == Alloc::external_pointer<Start>(p));
sz = (std::min)(size, sz);
sz = bits::min(size, sz);
memcpy(p, ptr, sz);
SNMALLOC_NAME_MANGLE(free)(ptr);
}
@@ -135,7 +136,7 @@ extern "C"
return nullptr;
}
size = (std::max)(size, alignment);
size = bits::max(size, alignment);
uint8_t sc = size_to_sizeclass(size);
if (sc >= NUM_SIZECLASSES)
{

View File

@@ -5,10 +5,11 @@
# include "../mem/allocconfig.h"
# include <pthread.h>
# include <stdio.h>
# include <strings.h>
# include <sys/mman.h>
int puts ( const char * str );
namespace snmalloc
{
/**

View File

@@ -4,7 +4,6 @@
# include "../ds/bits.h"
# include "../mem/allocconfig.h"
# include <pthread.h>
# include <stdio.h>
# include <strings.h>
# include <sys/mman.h>

View File

@@ -4,10 +4,11 @@
# include "../ds/bits.h"
# include "../mem/allocconfig.h"
# include <stdio.h>
# include <string.h>
# include <sys/mman.h>
int puts ( const char * str );
namespace snmalloc
{
class PALLinux