0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 22:18:54 +02:00

ircd::ios: Add hook for is_continuation; minor reorg.

This commit is contained in:
Jason Volk 2019-03-28 16:56:55 -07:00
parent 83593c5533
commit 79065f805b
2 changed files with 43 additions and 20 deletions

View file

@ -86,10 +86,12 @@ struct ircd::ios::descriptor
std::function<void *(handler &, const size_t &)> allocator;
std::function<void (handler &, void *const &, const size_t &)> deallocator;
bool continuation;
descriptor(const string_view &name,
const decltype(allocator) & = default_allocator,
const decltype(deallocator) & = default_deallocator);
const decltype(deallocator) & = default_deallocator,
const bool &continuation = false);
descriptor(descriptor &&) = delete;
descriptor(const descriptor &) = delete;
@ -102,6 +104,7 @@ struct ircd::ios::handler
static void *allocate(handler *const &, const size_t &);
static void deallocate(handler *const &, void *const &, const size_t &);
static bool continuation(handler *const &);
static void enter(handler *const &);
static void leave(handler *const &);
static bool fault(handler *const &);
@ -130,6 +133,9 @@ namespace ircd::ios
template<class function>
void *asio_handler_allocate(size_t, handle<function> *);
template<class function>
bool asio_handler_is_continuation(handle<function> *);
template<class callable,
class function>
void asio_handler_invoke(callable &f, handle<function> *);
@ -151,24 +157,6 @@ const
f(std::forward<args>(a)...);
}
template<class function>
void
ircd::ios::asio_handler_deallocate(void *const ptr,
size_t size,
handle<function> *const h)
{
handler::deallocate(h, ptr, size);
}
template<class function>
void *
__attribute__((malloc, returns_nonnull, warn_unused_result, alloc_size(1)))
ircd::ios::asio_handler_allocate(size_t size,
handle<function> *const h)
{
return handler::allocate(h, size);
}
template<class callable,
class function>
void
@ -188,6 +176,31 @@ catch(...)
throw;
}
template<class function>
bool
ircd::ios::asio_handler_is_continuation(handle<function> *const h)
{
return handler::continuation(h);
}
template<class function>
void *
__attribute__((malloc, returns_nonnull, warn_unused_result, alloc_size(1)))
ircd::ios::asio_handler_allocate(size_t size,
handle<function> *const h)
{
return handler::allocate(h, size);
}
template<class function>
void
ircd::ios::asio_handler_deallocate(void *const ptr,
size_t size,
handle<function> *const h)
{
handler::deallocate(h, ptr, size);
}
inline void
ircd::ios::assert_main_thread()
{

View file

@ -126,10 +126,12 @@ ircd::ios::descriptor::ids;
ircd::ios::descriptor::descriptor(const string_view &name,
const decltype(allocator) &allocator,
const decltype(deallocator) &deallocator)
const decltype(deallocator) &deallocator,
const bool &continuation)
:name{name}
,allocator{allocator}
,deallocator{deallocator}
,continuation{continuation}
{
assert(allocator);
assert(deallocator);
@ -203,6 +205,14 @@ ircd::ios::handler::enter(handler *const &handler)
handler->slice_start = cycles();
}
bool
ircd::ios::handler::continuation(handler *const &handler)
{
assert(handler && handler->descriptor);
auto &descriptor(*handler->descriptor);
return descriptor.continuation;
}
void
ircd::ios::handler::deallocate(handler *const &handler,
void *const &ptr,