mirror of
https://github.com/Icinga/icinga2.git
synced 2025-12-18 03:03:53 +01:00
Introduce DefaultAllocator
This commit is contained in:
parent
97eda30f86
commit
4fd8c92a13
@ -23,6 +23,7 @@ struct DAPage
|
|||||||
|
|
||||||
static thread_local struct {
|
static thread_local struct {
|
||||||
unsigned int InUse = 0;
|
unsigned int InUse = 0;
|
||||||
|
unsigned int Paused = 0;
|
||||||
DAPage* TopPage = nullptr;
|
DAPage* TopPage = nullptr;
|
||||||
} l_DefragAllocator;
|
} l_DefragAllocator;
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ extern "C" void* malloc(size_t bytes)
|
|||||||
static const auto libcMalloc = (void*(*)(size_t))dlsym(RTLD_NEXT, "malloc");
|
static const auto libcMalloc = (void*(*)(size_t))dlsym(RTLD_NEXT, "malloc");
|
||||||
static const size_t pageSize = std::max(128L * 1024L, sysconf(_SC_PAGESIZE));
|
static const size_t pageSize = std::max(128L * 1024L, sysconf(_SC_PAGESIZE));
|
||||||
|
|
||||||
if (BOOST_LIKELY(!l_DefragAllocator.InUse)) {
|
if (BOOST_LIKELY(!l_DefragAllocator.InUse || l_DefragAllocator.Paused)) {
|
||||||
return libcMalloc(bytes);
|
return libcMalloc(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ extern "C" void free(void* memory)
|
|||||||
{
|
{
|
||||||
static const auto libcFree = (void(*)(void*))dlsym(RTLD_NEXT, "free");
|
static const auto libcFree = (void(*)(void*))dlsym(RTLD_NEXT, "free");
|
||||||
|
|
||||||
if (BOOST_LIKELY(!l_DefragAllocator.InUse)) {
|
if (BOOST_LIKELY(!l_DefragAllocator.InUse || l_DefragAllocator.Paused)) {
|
||||||
libcFree(memory);
|
libcFree(memory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,4 +98,14 @@ DefragAllocator::~DefragAllocator()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefaultAllocator::DefaultAllocator()
|
||||||
|
{
|
||||||
|
++l_DefragAllocator.Paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultAllocator::~DefaultAllocator()
|
||||||
|
{
|
||||||
|
--l_DefragAllocator.Paused;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|||||||
@ -21,4 +21,20 @@ public:
|
|||||||
~DefragAllocator();
|
~DefragAllocator();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
|
class DefaultAllocator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DefaultAllocator();
|
||||||
|
DefaultAllocator(const DefaultAllocator&) = delete;
|
||||||
|
DefaultAllocator(DefaultAllocator&&) = delete;
|
||||||
|
DefaultAllocator& operator=(const DefaultAllocator&) = delete;
|
||||||
|
DefaultAllocator& operator=(DefaultAllocator&&) = delete;
|
||||||
|
~DefaultAllocator();
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user