From 387e8b8eed3c2fde14c0405a5fd6d4cd44080ec1 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 24 Dec 2018 12:06:05 -0800 Subject: [PATCH] ircd::ctx: Improve pool loop; improve log msg; add interruption point. --- include/ircd/ctx/pool.h | 2 +- ircd/ctx.cc | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/ircd/ctx/pool.h b/include/ircd/ctx/pool.h index 8ff7df836..7646d99a7 100644 --- a/include/ircd/ctx/pool.h +++ b/include/ircd/ctx/pool.h @@ -29,7 +29,7 @@ class ircd::ctx::pool queue q; std::vector ctxs; - void next(); + void work(); void main() noexcept; public: diff --git a/ircd/ctx.cc b/ircd/ctx.cc index 52a085e03..de10a7378 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -1310,6 +1310,7 @@ ircd::ctx::pool::operator()(closure closure) q.push(std::move(closure)); } +/// Main execution loop for a pool. void ircd::ctx::pool::main() noexcept try @@ -1321,7 +1322,7 @@ noexcept try }); while(1) - next(); + work(); } catch(const interrupted &e) { @@ -1334,12 +1335,12 @@ catch(const terminated &e) { // log::debug // { -// "pool(%p) ctx(%p): %s", this, &cur(), e.what() +// "pool(%p) ctx(%p): terminated", this, &cur() // }; } void -ircd::ctx::pool::next() +ircd::ctx::pool::work() try { const auto func @@ -1353,7 +1354,12 @@ try --working; }); + // Execute the user's function func(); + + // Check for latent interruption to this ctx. If there's anything pending + // it's best to get rid of it sooner rather than later. + interruption_point(); } catch(const interrupted &e) { @@ -1364,8 +1370,9 @@ catch(const std::exception &e) { log::critical { - "pool(%p) ctx(%p '%s' id:%u): unhandled: %s", + "pool(%p '%s') ctx(%p '%s' id:%u): unhandled: %s", this, + name, current, ircd::ctx::name(cur()), ircd::ctx::id(cur()),