mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 06:51:08 +01:00
ircd::ctx: Optimize asio timer cancel action for ctx::wake().
This commit is contained in:
parent
8f5b40e9d5
commit
ea30ee38f9
1 changed files with 34 additions and 0 deletions
34
ircd/ctx.cc
34
ircd/ctx.cc
|
@ -281,6 +281,40 @@ catch(const std::exception &e)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optimize ctx::wake() by reimplementing the timer cancel's op scheduler to
|
||||||
|
// enqueue as a defer (private/priority queue) rather than to the post queue.
|
||||||
|
#if defined(BOOST_ASIO_HAS_EPOLL)
|
||||||
|
using epoll_time_traits = boost::asio::time_traits<boost::posix_time::ptime>;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline std::size_t
|
||||||
|
boost::asio::detail::epoll_reactor::cancel_timer(timer_queue<epoll_time_traits> &queue,
|
||||||
|
typename timer_queue<epoll_time_traits>::per_timer_data &t,
|
||||||
|
std::size_t max)
|
||||||
|
{
|
||||||
|
std::size_t ret;
|
||||||
|
op_queue<operation> ops;
|
||||||
|
{
|
||||||
|
const mutex::scoped_lock lock(mutex_);
|
||||||
|
ret = queue.cancel_timer(t, ops, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *const thread_info
|
||||||
|
{
|
||||||
|
static_cast<scheduler_thread_info *>(scheduler::thread_call_stack::top())
|
||||||
|
};
|
||||||
|
|
||||||
|
for(auto *op(ops.front()); op; ops.pop(), op = ops.front())
|
||||||
|
{
|
||||||
|
static const bool is_continuation(true);
|
||||||
|
scheduler_.post_immediate_completion(op, is_continuation);
|
||||||
|
thread_info->private_outstanding_work -= is_continuation;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Throws if this context has been flagged for interruption and clears
|
/// Throws if this context has been flagged for interruption and clears
|
||||||
/// the flag.
|
/// the flag.
|
||||||
[[gnu::hot]]
|
[[gnu::hot]]
|
||||||
|
|
Loading…
Reference in a new issue