mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 00:32:35 +01:00
ircd::ios: Add interface for user allocation closure at descriptor site.
This commit is contained in:
parent
02f413c834
commit
3225c1fdfe
2 changed files with 34 additions and 4 deletions
|
@ -70,6 +70,9 @@ struct ircd::ios::descriptor
|
|||
{
|
||||
static uint64_t ids;
|
||||
|
||||
static void *default_allocator(handler &, const size_t &);
|
||||
static void default_deallocator(handler &, void *const &, const size_t &);
|
||||
|
||||
string_view name;
|
||||
uint64_t id {++ids};
|
||||
uint64_t calls {0};
|
||||
|
@ -81,7 +84,13 @@ struct ircd::ios::descriptor
|
|||
uint64_t slice_total {0};
|
||||
uint64_t slice_last {0};
|
||||
|
||||
descriptor(const string_view &name);
|
||||
std::function<void *(handler &, const size_t &)> allocator;
|
||||
std::function<void (handler &, void *const &, const size_t &)> deallocator;
|
||||
|
||||
descriptor(const string_view &name,
|
||||
const decltype(allocator) & = default_allocator,
|
||||
const decltype(deallocator) & = default_deallocator);
|
||||
|
||||
descriptor(descriptor &&) = delete;
|
||||
descriptor(const descriptor &) = delete;
|
||||
~descriptor() noexcept;
|
||||
|
|
27
ircd/ios.cc
27
ircd/ios.cc
|
@ -124,9 +124,15 @@ ircd::ios::descriptor::ids;
|
|||
// descriptor::descriptor
|
||||
//
|
||||
|
||||
ircd::ios::descriptor::descriptor(const string_view &name)
|
||||
ircd::ios::descriptor::descriptor(const string_view &name,
|
||||
const decltype(allocator) &allocator,
|
||||
const decltype(deallocator) &deallocator)
|
||||
:name{name}
|
||||
,allocator{allocator}
|
||||
,deallocator{deallocator}
|
||||
{
|
||||
assert(allocator);
|
||||
assert(deallocator);
|
||||
}
|
||||
|
||||
ircd::ios::descriptor::~descriptor()
|
||||
|
@ -134,6 +140,21 @@ noexcept
|
|||
{
|
||||
}
|
||||
|
||||
void
|
||||
ircd::ios::descriptor::default_deallocator(handler &handler,
|
||||
void *const &ptr,
|
||||
const size_t &size)
|
||||
{
|
||||
::operator delete(ptr, size);
|
||||
}
|
||||
|
||||
void *
|
||||
ircd::ios::descriptor::default_allocator(handler &handler,
|
||||
const size_t &size)
|
||||
{
|
||||
return ::operator new(size);
|
||||
}
|
||||
|
||||
//
|
||||
// handler
|
||||
//
|
||||
|
@ -189,7 +210,7 @@ ircd::ios::handler::deallocate(handler *const &handler,
|
|||
{
|
||||
assert(handler && handler->descriptor);
|
||||
auto &descriptor(*handler->descriptor);
|
||||
::operator delete(ptr, size);
|
||||
descriptor.deallocator(*handler, ptr, size);
|
||||
descriptor.free_bytes += size;
|
||||
++descriptor.frees;
|
||||
}
|
||||
|
@ -202,5 +223,5 @@ ircd::ios::handler::allocate(handler *const &handler,
|
|||
auto &descriptor(*handler->descriptor);
|
||||
descriptor.alloc_bytes += size;
|
||||
++descriptor.allocs;
|
||||
return ::operator new(size);
|
||||
return descriptor.allocator(*handler, size);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue