0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00

ircd::ios: Inline additional handler related definitions.

This commit is contained in:
Jason Volk 2020-12-11 13:58:22 -08:00
parent dac50c8da7
commit 5151a3b934
2 changed files with 66 additions and 57 deletions

View file

@ -119,7 +119,7 @@ struct ircd::ios::descriptor
descriptor(const string_view &name,
const decltype(allocator) & = default_allocator,
const decltype(deallocator) & = default_deallocator,
const bool &continuation = false);
const bool &continuation = false) noexcept;
descriptor(descriptor &&) = delete;
descriptor(const descriptor &) = delete;
@ -267,6 +267,43 @@ const
// ircd::ios::handler
//
[[gnu::hot]]
inline void
ircd::ios::handler::deallocate(handler *const &handler,
void *const &ptr,
const size_t &size)
noexcept
{
assert(handler && handler->descriptor);
auto &descriptor(*handler->descriptor);
assert(descriptor.deallocator);
descriptor.deallocator(*handler, ptr, size);
assert(descriptor.stats);
auto &stats(*descriptor.stats);
stats.free_bytes += size;
++stats.frees;
}
[[gnu::hot]]
inline void *
ircd::ios::handler::allocate(handler *const &handler,
const size_t &size)
{
assert(handler && handler->descriptor);
auto &descriptor(*handler->descriptor);
assert(descriptor.stats);
auto &stats(*descriptor.stats);
stats.alloc_bytes += size;
++stats.allocs;
assert(descriptor.allocator);
return descriptor.allocator(*handler, size);
}
[[gnu::hot]]
inline void
ircd::ios::handler::enqueue(handler *const &handler)
noexcept
@ -291,6 +328,7 @@ noexcept
};
}
[[gnu::hot]]
inline bool
ircd::ios::handler::continuation(handler *const &handler)
noexcept
@ -300,6 +338,32 @@ noexcept
return descriptor.continuation;
}
//
// ios::descriptor
//
[[gnu::hot]]
inline void
ircd::ios::descriptor::default_deallocator(handler &handler,
void *const &ptr,
const size_t &size)
noexcept
{
#ifdef __clang__
::operator delete(ptr);
#else
::operator delete(ptr, size);
#endif
}
[[gnu::hot]]
inline void *
ircd::ios::descriptor::default_allocator(handler &handler,
const size_t &size)
{
return ::operator new(size);
}
//
// ircd::ios
//

View file

@ -91,6 +91,7 @@ ircd::ios::descriptor::descriptor(const string_view &name,
const decltype(allocator) &allocator,
const decltype(deallocator) &deallocator,
const bool &continuation)
noexcept
:name
{
name
@ -130,28 +131,6 @@ noexcept
assert(!stats || stats->alloc_bytes == stats->free_bytes);
}
[[gnu::hot]]
void
ircd::ios::descriptor::default_deallocator(handler &handler,
void *const &ptr,
const size_t &size)
noexcept
{
#ifdef __clang__
::operator delete(ptr);
#else
::operator delete(ptr, size);
#endif
}
[[gnu::hot]]
void *
ircd::ios::descriptor::default_allocator(handler &handler,
const size_t &size)
{
return ::operator new(size);
}
//
// descriptor::stats
//
@ -315,40 +294,6 @@ noexcept
};
}
[[gnu::hot]]
void
ircd::ios::handler::deallocate(handler *const &handler,
void *const &ptr,
const size_t &size)
noexcept
{
assert(handler && handler->descriptor);
auto &descriptor(*handler->descriptor);
descriptor.deallocator(*handler, ptr, size);
assert(descriptor.stats);
auto &stats(*descriptor.stats);
stats.free_bytes += size;
++stats.frees;
}
[[gnu::hot]]
void *
ircd::ios::handler::allocate(handler *const &handler,
const size_t &size)
{
assert(handler && handler->descriptor);
auto &descriptor(*handler->descriptor);
assert(descriptor.stats);
auto &stats(*descriptor.stats);
stats.alloc_bytes += size;
++stats.allocs;
return descriptor.allocator(*handler, size);
}
//
// ios.h
//