2018-10-17 14:12:10 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
2020-12-07 20:19:33 +01:00
|
|
|
/// Logging facility
|
|
|
|
decltype(ircd::ios::log)
|
|
|
|
ircd::ios::log
|
|
|
|
{
|
|
|
|
"ios"
|
|
|
|
};
|
|
|
|
|
2018-10-17 14:12:10 +02:00
|
|
|
/// "main" thread for IRCd; the one the main context landed on.
|
|
|
|
decltype(ircd::ios::main_thread_id)
|
|
|
|
ircd::ios::main_thread_id;
|
|
|
|
|
2020-02-27 19:11:59 +01:00
|
|
|
/// The embedder/executable's (library user) asio::executor provided on init.
|
2018-10-17 14:12:10 +02:00
|
|
|
decltype(ircd::ios::user)
|
|
|
|
ircd::ios::user;
|
|
|
|
|
2020-02-27 19:11:59 +01:00
|
|
|
/// Our library-specific/isolate executor.
|
|
|
|
decltype(ircd::ios::main)
|
|
|
|
ircd::ios::main;
|
|
|
|
|
2019-06-01 01:06:55 +02:00
|
|
|
decltype(ircd::boost_version_api)
|
|
|
|
ircd::boost_version_api
|
|
|
|
{
|
|
|
|
"boost", info::versions::API, BOOST_VERSION,
|
|
|
|
{
|
|
|
|
BOOST_VERSION / 100000,
|
|
|
|
BOOST_VERSION / 100 % 1000,
|
|
|
|
BOOST_VERSION % 100,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::boost_version_abi)
|
|
|
|
ircd::boost_version_abi
|
|
|
|
{
|
2019-06-02 23:21:40 +02:00
|
|
|
"boost", info::versions::ABI //TODO: get this
|
2019-06-01 01:06:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// init
|
|
|
|
//
|
|
|
|
|
2018-10-17 14:12:10 +02:00
|
|
|
void
|
2020-02-27 19:11:59 +01:00
|
|
|
ircd::ios::init(asio::executor &&user)
|
2018-10-17 14:12:10 +02:00
|
|
|
{
|
|
|
|
// Sample the ID of this thread. Since this is the first transfer of
|
|
|
|
// control to libircd after static initialization we have nothing to
|
|
|
|
// consider a main thread yet. We need something set for many assertions
|
2020-05-05 01:07:30 +02:00
|
|
|
// to pass.
|
2018-10-17 14:12:10 +02:00
|
|
|
main_thread_id = std::this_thread::get_id();
|
|
|
|
|
|
|
|
// Set a reference to the user's ios_service
|
2020-02-27 19:11:59 +01:00
|
|
|
ios::user = std::move(user);
|
|
|
|
|
|
|
|
// (simple passthru for now)
|
|
|
|
ios::main = ios::user;
|
2018-10-17 14:12:10 +02:00
|
|
|
}
|
|
|
|
|
2019-03-27 00:53:31 +01:00
|
|
|
//
|
|
|
|
// descriptor
|
|
|
|
//
|
|
|
|
|
2019-04-17 05:48:00 +02:00
|
|
|
template<>
|
|
|
|
decltype(ircd::util::instance_list<ircd::ios::descriptor>::allocator)
|
|
|
|
ircd::util::instance_list<ircd::ios::descriptor>::allocator
|
|
|
|
{};
|
|
|
|
|
2019-03-27 00:53:31 +01:00
|
|
|
template<>
|
|
|
|
decltype(ircd::util::instance_list<ircd::ios::descriptor>::list)
|
|
|
|
ircd::util::instance_list<ircd::ios::descriptor>::list
|
2019-04-17 05:48:00 +02:00
|
|
|
{
|
|
|
|
allocator
|
|
|
|
};
|
2019-03-27 00:53:31 +01:00
|
|
|
|
|
|
|
decltype(ircd::ios::descriptor::ids)
|
|
|
|
ircd::ios::descriptor::ids;
|
|
|
|
|
|
|
|
//
|
|
|
|
// descriptor::descriptor
|
|
|
|
//
|
|
|
|
|
2019-03-27 10:49:28 +01:00
|
|
|
ircd::ios::descriptor::descriptor(const string_view &name,
|
|
|
|
const decltype(allocator) &allocator,
|
2019-03-29 00:56:55 +01:00
|
|
|
const decltype(deallocator) &deallocator,
|
|
|
|
const bool &continuation)
|
2020-12-11 22:58:22 +01:00
|
|
|
noexcept
|
2019-09-22 23:41:31 +02:00
|
|
|
:name
|
|
|
|
{
|
|
|
|
name
|
|
|
|
}
|
|
|
|
,stats
|
|
|
|
{
|
|
|
|
std::make_unique<struct stats>()
|
|
|
|
}
|
|
|
|
,allocator
|
|
|
|
{
|
|
|
|
allocator?: default_allocator
|
|
|
|
}
|
|
|
|
,deallocator
|
|
|
|
{
|
|
|
|
deallocator?: default_deallocator
|
|
|
|
}
|
2020-08-02 14:45:35 +02:00
|
|
|
,history
|
|
|
|
(
|
|
|
|
256, {0}
|
|
|
|
)
|
2020-08-21 03:00:48 +02:00
|
|
|
,history_pos
|
|
|
|
{
|
|
|
|
0
|
|
|
|
}
|
2019-09-22 23:41:31 +02:00
|
|
|
,continuation
|
|
|
|
{
|
|
|
|
continuation
|
|
|
|
}
|
2019-03-27 00:53:31 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::descriptor::~descriptor()
|
|
|
|
noexcept
|
|
|
|
{
|
2020-10-06 06:27:28 +02:00
|
|
|
assert(!stats || stats->queued == 0);
|
|
|
|
assert(!stats || stats->allocs == stats->frees);
|
|
|
|
assert(!stats || stats->alloc_bytes == stats->free_bytes);
|
2019-03-27 00:53:31 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 01:09:46 +01:00
|
|
|
//
|
|
|
|
// descriptor::stats
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::ios::descriptor::stats::stats()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::descriptor::stats::~stats()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-29 01:16:47 +01:00
|
|
|
struct ircd::ios::descriptor::stats &
|
2019-03-29 01:09:46 +01:00
|
|
|
ircd::ios::descriptor::stats::operator+=(const stats &o)
|
|
|
|
&
|
|
|
|
{
|
2019-04-11 07:52:33 +02:00
|
|
|
queued += o.queued;
|
2019-03-29 01:09:46 +01:00
|
|
|
calls += o.calls;
|
|
|
|
faults += o.faults;
|
|
|
|
allocs += o.allocs;
|
|
|
|
alloc_bytes += o.alloc_bytes;
|
|
|
|
frees += o.frees;
|
|
|
|
free_bytes += o.free_bytes;
|
|
|
|
slice_total += o.slice_total;
|
|
|
|
slice_last += o.slice_last;
|
2019-09-22 23:43:14 +02:00
|
|
|
latency_total += o.latency_total;
|
|
|
|
latency_last += o.latency_last;
|
2019-03-29 01:09:46 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-03-27 00:53:31 +01:00
|
|
|
//
|
|
|
|
// handler
|
|
|
|
//
|
|
|
|
|
2019-07-16 01:02:40 +02:00
|
|
|
decltype(ircd::ios::handler::current)
|
|
|
|
thread_local
|
2019-03-27 10:06:55 +01:00
|
|
|
ircd::ios::handler::current;
|
|
|
|
|
2019-07-16 01:02:40 +02:00
|
|
|
decltype(ircd::ios::handler::epoch)
|
|
|
|
thread_local
|
|
|
|
ircd::ios::handler::epoch;
|
|
|
|
|
2019-09-11 00:11:25 +02:00
|
|
|
[[gnu::cold]]
|
2019-03-27 00:53:31 +01:00
|
|
|
bool
|
|
|
|
ircd::ios::handler::fault(handler *const &handler)
|
2019-07-16 01:01:35 +02:00
|
|
|
noexcept
|
2019-03-27 00:53:31 +01:00
|
|
|
{
|
|
|
|
assert(handler && handler->descriptor);
|
|
|
|
auto &descriptor(*handler->descriptor);
|
2019-03-27 06:03:48 +01:00
|
|
|
|
2019-03-29 01:09:46 +01:00
|
|
|
assert(descriptor.stats);
|
|
|
|
auto &stats(*descriptor.stats);
|
|
|
|
++stats.faults;
|
|
|
|
|
2020-12-09 02:54:34 +01:00
|
|
|
bool ret
|
2019-03-27 06:03:48 +01:00
|
|
|
{
|
2020-12-09 02:54:34 +01:00
|
|
|
false
|
|
|
|
};
|
|
|
|
|
|
|
|
if constexpr(profile_logging)
|
|
|
|
log::logf
|
2020-08-21 13:18:41 +02:00
|
|
|
{
|
2020-12-09 02:54:34 +01:00
|
|
|
log, log::level::DEBUG,
|
2020-12-12 05:49:36 +01:00
|
|
|
"FAULT %5u %-30s [%11lu] faults[%9lu] q:%-4lu",
|
2020-12-09 02:54:34 +01:00
|
|
|
descriptor.id,
|
2020-12-12 05:49:36 +01:00
|
|
|
trunc(descriptor.name, 30),
|
2020-12-09 02:54:34 +01:00
|
|
|
stats.calls,
|
|
|
|
stats.faults,
|
|
|
|
stats.queued,
|
2020-08-21 13:18:41 +02:00
|
|
|
};
|
|
|
|
|
2020-12-09 02:54:34 +01:00
|
|
|
// Our API sez if this function returns true, caller is responsible for
|
|
|
|
// calling leave(), otherwise they must not call leave().
|
|
|
|
if(likely(!ret))
|
|
|
|
leave(handler);
|
2019-03-27 06:03:48 +01:00
|
|
|
|
|
|
|
return ret;
|
2019-03-27 00:53:31 +01:00
|
|
|
}
|
|
|
|
|
2019-09-11 00:11:25 +02:00
|
|
|
[[gnu::hot]]
|
2019-03-27 00:53:31 +01:00
|
|
|
void
|
|
|
|
ircd::ios::handler::leave(handler *const &handler)
|
2019-07-16 01:01:35 +02:00
|
|
|
noexcept
|
2019-03-27 00:53:31 +01:00
|
|
|
{
|
|
|
|
assert(handler && handler->descriptor);
|
|
|
|
auto &descriptor(*handler->descriptor);
|
2019-03-29 01:09:46 +01:00
|
|
|
|
|
|
|
assert(descriptor.stats);
|
|
|
|
auto &stats(*descriptor.stats);
|
2019-09-15 03:15:09 +02:00
|
|
|
|
2020-08-21 13:18:41 +02:00
|
|
|
const auto slice_start
|
2019-09-22 23:43:14 +02:00
|
|
|
{
|
2020-08-21 13:18:41 +02:00
|
|
|
std::exchange(handler->ts, cycles())
|
2019-09-22 23:43:14 +02:00
|
|
|
};
|
|
|
|
|
2019-09-15 03:15:09 +02:00
|
|
|
// NOTE: will fail without constant_tsc;
|
|
|
|
// NOTE: may fail without nonstop_tsc after OS suspend mode
|
2020-08-21 13:18:41 +02:00
|
|
|
assert(handler->ts >= slice_start);
|
|
|
|
stats.slice_last = handler->ts - slice_start;
|
2019-03-29 01:09:46 +01:00
|
|
|
stats.slice_total += stats.slice_last;
|
|
|
|
|
2020-08-02 14:45:35 +02:00
|
|
|
if constexpr(profile_history)
|
|
|
|
{
|
|
|
|
assert(descriptor.history_pos < descriptor.history.size());
|
|
|
|
descriptor.history[descriptor.history_pos][0] = handler::epoch;
|
|
|
|
descriptor.history[descriptor.history_pos][1] = stats.slice_last;
|
|
|
|
++descriptor.history_pos;
|
|
|
|
}
|
|
|
|
|
2020-12-09 02:54:34 +01:00
|
|
|
if constexpr(profile_logging)
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DEBUG,
|
2020-12-12 05:49:36 +01:00
|
|
|
"LEAVE %5u %-30s [%11lu] cycles[%9lu] q:%-4lu",
|
2020-12-09 02:54:34 +01:00
|
|
|
descriptor.id,
|
2020-12-12 05:49:36 +01:00
|
|
|
trunc(descriptor.name, 30),
|
2020-12-09 02:54:34 +01:00
|
|
|
stats.calls,
|
|
|
|
stats.slice_last,
|
|
|
|
stats.queued,
|
|
|
|
};
|
|
|
|
|
2019-03-27 10:06:55 +01:00
|
|
|
assert(handler::current == handler);
|
|
|
|
handler::current = nullptr;
|
2019-03-27 00:53:31 +01:00
|
|
|
}
|
|
|
|
|
2019-09-11 00:11:25 +02:00
|
|
|
[[gnu::hot]]
|
2019-03-27 00:53:31 +01:00
|
|
|
void
|
|
|
|
ircd::ios::handler::enter(handler *const &handler)
|
2019-07-16 01:01:35 +02:00
|
|
|
noexcept
|
2019-03-27 00:53:31 +01:00
|
|
|
{
|
2019-09-22 23:43:14 +02:00
|
|
|
assert(!handler::current);
|
2020-08-02 14:45:35 +02:00
|
|
|
handler::current = handler;
|
|
|
|
++handler::epoch;
|
|
|
|
|
2019-03-27 00:53:31 +01:00
|
|
|
assert(handler && handler->descriptor);
|
|
|
|
auto &descriptor(*handler->descriptor);
|
2019-03-29 01:09:46 +01:00
|
|
|
|
|
|
|
assert(descriptor.stats);
|
|
|
|
auto &stats(*descriptor.stats);
|
2019-09-22 23:43:14 +02:00
|
|
|
++stats.calls;
|
|
|
|
|
|
|
|
const auto last_ts
|
|
|
|
{
|
|
|
|
std::exchange(handler->ts, cycles())
|
|
|
|
};
|
|
|
|
|
|
|
|
stats.latency_last = handler->ts - last_ts;
|
|
|
|
stats.latency_total += stats.latency_last;
|
2019-03-27 05:22:22 +01:00
|
|
|
|
2020-12-09 02:54:34 +01:00
|
|
|
if constexpr(profile_logging)
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, log::level::DEBUG,
|
2020-12-12 05:49:36 +01:00
|
|
|
"ENTER %5u %-30s [%11lu] latent[%9lu] q:%-4lu",
|
2020-12-09 02:54:34 +01:00
|
|
|
descriptor.id,
|
2020-12-12 05:49:36 +01:00
|
|
|
trunc(descriptor.name, 30),
|
2020-12-09 02:54:34 +01:00
|
|
|
stats.calls,
|
|
|
|
stats.latency_last,
|
|
|
|
stats.queued,
|
|
|
|
};
|
2019-03-29 00:56:55 +01:00
|
|
|
}
|
|
|
|
|
2019-05-16 08:20:13 +02:00
|
|
|
//
|
|
|
|
// ios.h
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace ircd::ios
|
|
|
|
{
|
|
|
|
extern descriptor post_desc;
|
|
|
|
extern descriptor defer_desc;
|
|
|
|
extern descriptor dispatch_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::ios::forking()
|
|
|
|
{
|
2020-02-27 19:11:59 +01:00
|
|
|
#if BOOST_VERSION >= 107000
|
|
|
|
get().context().notify_fork(asio::execution_context::fork_prepare);
|
|
|
|
#else
|
|
|
|
get().notify_fork(asio::execution_context::fork_prepare);
|
|
|
|
#endif
|
2019-05-16 08:20:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::ios::forked_child()
|
|
|
|
{
|
2020-02-27 19:11:59 +01:00
|
|
|
#if BOOST_VERSION >= 107000
|
|
|
|
get().context().notify_fork(asio::execution_context::fork_child);
|
|
|
|
#else
|
|
|
|
get().notify_fork(asio::execution_context::fork_child);
|
|
|
|
#endif
|
2019-05-16 08:20:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::ios::forked_parent()
|
|
|
|
{
|
2020-02-27 19:11:59 +01:00
|
|
|
#if BOOST_VERSION >= 107000
|
|
|
|
get().context().notify_fork(asio::execution_context::fork_parent);
|
|
|
|
#else
|
|
|
|
get().notify_fork(asio::execution_context::fork_parent);
|
|
|
|
#endif
|
2019-05-16 08:20:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// dispatch
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::ios::dispatch_desc)
|
|
|
|
ircd::ios::dispatch_desc
|
|
|
|
{
|
|
|
|
"ircd::ios dispatch"
|
|
|
|
};
|
|
|
|
|
2019-09-11 00:11:25 +02:00
|
|
|
[[gnu::hot]]
|
2019-05-16 08:20:13 +02:00
|
|
|
ircd::ios::dispatch::dispatch(std::function<void ()> function)
|
2019-07-06 02:34:42 +02:00
|
|
|
:dispatch
|
|
|
|
{
|
|
|
|
dispatch_desc, std::move(function)
|
|
|
|
}
|
2019-05-16 08:20:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::dispatch::dispatch(synchronous_t,
|
|
|
|
const std::function<void ()> &function)
|
2019-07-06 02:34:42 +02:00
|
|
|
:dispatch
|
|
|
|
{
|
|
|
|
dispatch_desc, synchronous, std::move(function)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::dispatch::dispatch(descriptor &descriptor,
|
|
|
|
synchronous_t)
|
|
|
|
:dispatch
|
|
|
|
{
|
|
|
|
dispatch_desc, synchronous, []
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2019-05-16 08:20:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::dispatch::dispatch(descriptor &descriptor,
|
|
|
|
synchronous_t,
|
|
|
|
const std::function<void ()> &function)
|
|
|
|
{
|
2020-08-23 13:20:48 +02:00
|
|
|
const ctx::uninterruptible ui;
|
2019-05-16 08:20:13 +02:00
|
|
|
|
2020-08-23 13:20:48 +02:00
|
|
|
assert(function);
|
|
|
|
ctx::continuation
|
2019-05-16 08:20:13 +02:00
|
|
|
{
|
2020-08-23 13:20:48 +02:00
|
|
|
continuation::false_predicate, continuation::noop_interruptor, [&descriptor, &function]
|
|
|
|
(auto &yield)
|
2019-05-16 08:20:13 +02:00
|
|
|
{
|
2020-08-23 13:20:48 +02:00
|
|
|
dispatch(descriptor, [&function]
|
|
|
|
{
|
|
|
|
function();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2019-05-16 08:20:13 +02:00
|
|
|
}
|
|
|
|
|
2019-09-11 00:11:25 +02:00
|
|
|
[[gnu::hot]]
|
2019-05-16 08:20:13 +02:00
|
|
|
ircd::ios::dispatch::dispatch(descriptor &descriptor,
|
|
|
|
std::function<void ()> function)
|
|
|
|
{
|
|
|
|
boost::asio::dispatch(get(), handle(descriptor, std::move(function)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// defer
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::ios::defer_desc)
|
|
|
|
ircd::ios::defer_desc
|
|
|
|
{
|
2020-02-25 20:37:49 +01:00
|
|
|
"ircd::ios defer",
|
|
|
|
descriptor::default_allocator,
|
|
|
|
descriptor::default_deallocator,
|
|
|
|
true, // continuation
|
2019-05-16 08:20:13 +02:00
|
|
|
};
|
|
|
|
|
2019-09-11 00:11:25 +02:00
|
|
|
[[gnu::hot]]
|
2019-05-16 08:20:13 +02:00
|
|
|
ircd::ios::defer::defer(std::function<void ()> function)
|
2019-07-06 02:34:42 +02:00
|
|
|
:defer
|
|
|
|
{
|
|
|
|
defer_desc, std::move(function)
|
|
|
|
}
|
2019-05-16 08:20:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::defer::defer(synchronous_t,
|
|
|
|
const std::function<void ()> &function)
|
2019-07-06 02:34:42 +02:00
|
|
|
:defer
|
|
|
|
{
|
|
|
|
defer_desc, synchronous, function
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::defer::defer(descriptor &descriptor,
|
|
|
|
synchronous_t)
|
|
|
|
:defer
|
|
|
|
{
|
|
|
|
defer_desc, synchronous, []
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2019-05-16 08:20:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::defer::defer(descriptor &descriptor,
|
|
|
|
synchronous_t,
|
|
|
|
const std::function<void ()> &function)
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
ctx::latch latch(1);
|
|
|
|
defer(descriptor, [&function, &latch]
|
|
|
|
{
|
|
|
|
const unwind uw{[&latch]
|
|
|
|
{
|
|
|
|
latch.count_down();
|
|
|
|
}};
|
|
|
|
|
|
|
|
function();
|
|
|
|
});
|
|
|
|
|
|
|
|
latch.wait();
|
|
|
|
}
|
|
|
|
|
2019-09-11 00:11:25 +02:00
|
|
|
[[gnu::hot]]
|
2019-05-16 08:20:13 +02:00
|
|
|
ircd::ios::defer::defer(descriptor &descriptor,
|
|
|
|
std::function<void ()> function)
|
|
|
|
{
|
|
|
|
boost::asio::defer(get(), handle(descriptor, std::move(function)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// post
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::ios::post_desc)
|
|
|
|
ircd::ios::post_desc
|
|
|
|
{
|
|
|
|
"ircd::ios post"
|
|
|
|
};
|
|
|
|
|
2019-09-11 00:11:25 +02:00
|
|
|
[[gnu::hot]]
|
2019-05-16 08:20:13 +02:00
|
|
|
ircd::ios::post::post(std::function<void ()> function)
|
2019-07-06 02:34:42 +02:00
|
|
|
:post
|
|
|
|
{
|
|
|
|
post_desc, std::move(function)
|
|
|
|
}
|
2019-05-16 08:20:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::post::post(synchronous_t,
|
|
|
|
const std::function<void ()> &function)
|
2019-07-06 02:34:42 +02:00
|
|
|
:post
|
|
|
|
{
|
|
|
|
post_desc, synchronous, function
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::post::post(descriptor &descriptor,
|
|
|
|
synchronous_t)
|
|
|
|
:post
|
|
|
|
{
|
|
|
|
descriptor, synchronous, []
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2019-05-16 08:20:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::ios::post::post(descriptor &descriptor,
|
|
|
|
synchronous_t,
|
|
|
|
const std::function<void ()> &function)
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
ctx::latch latch(1);
|
|
|
|
post(descriptor, [&function, &latch]
|
|
|
|
{
|
|
|
|
const unwind uw{[&latch]
|
|
|
|
{
|
|
|
|
latch.count_down();
|
|
|
|
}};
|
|
|
|
|
|
|
|
function();
|
|
|
|
});
|
|
|
|
|
|
|
|
latch.wait();
|
|
|
|
}
|
|
|
|
|
2019-09-11 00:11:25 +02:00
|
|
|
[[gnu::hot]]
|
2019-05-16 08:20:13 +02:00
|
|
|
ircd::ios::post::post(descriptor &descriptor,
|
|
|
|
std::function<void ()> function)
|
|
|
|
{
|
|
|
|
boost::asio::post(get(), handle(descriptor, std::move(function)));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::ios::available()
|
2019-08-06 01:15:56 +02:00
|
|
|
noexcept
|
2019-05-16 08:20:13 +02:00
|
|
|
{
|
2020-02-27 19:11:59 +01:00
|
|
|
return bool(main);
|
2019-05-16 08:20:13 +02:00
|
|
|
}
|