diff --git a/include/ircd/ctx/dock.h b/include/ircd/ctx/dock.h index 519185111..356ab843e 100644 --- a/include/ircd/ctx/dock.h +++ b/include/ircd/ctx/dock.h @@ -52,7 +52,7 @@ ircd::ctx::dock::wait_for(const duration &dur) static const duration zero(0); assert(current); - const unwind::exceptional renotify{[this] + const unwind_exceptional renotify{[this] { notify_one(); }}; @@ -78,7 +78,7 @@ ircd::ctx::dock::wait_for(const duration &dur, return true; assert(current); - const unwind::exceptional renotify{[this] + const unwind_exceptional renotify{[this] { notify_one(); }}; @@ -110,7 +110,7 @@ bool ircd::ctx::dock::wait_until(time_point&& tp) { assert(current); - const unwind::exceptional renotify{[this] + const unwind_exceptional renotify{[this] { notify_one(); }}; @@ -134,7 +134,7 @@ ircd::ctx::dock::wait_until(time_point&& tp, return true; assert(current); - const unwind::exceptional renotify{[this] + const unwind_exceptional renotify{[this] { notify_one(); }}; diff --git a/include/ircd/util/unwind.h b/include/ircd/util/unwind.h index 5c920d8b4..bcccfdf50 100644 --- a/include/ircd/util/unwind.h +++ b/include/ircd/util/unwind.h @@ -11,11 +11,18 @@ #pragma once #define HAVE_IRCD_UTIL_UNWIND_H -namespace ircd { -inline namespace util +namespace ircd { - struct unwind; -}} + inline namespace util + { + template struct unwind; + template struct unwind_nominal; + template struct unwind_exceptional; + struct unwind_defer; + struct unwind_nominal_assertion; + struct unwind_exceptional_assertion; + } +} // // Fundamental scope-unwind utilities establishing actions during destruction @@ -23,15 +30,11 @@ inline namespace util /// Unconditionally executes the provided code when the object goes out of scope. /// +template struct ircd::util::unwind { - struct defer; - struct nominal; - struct exceptional; + F func; - const std::function func; - - template unwind(F&& func) :func{std::forward(func)} {} @@ -49,24 +52,22 @@ struct ircd::util::unwind /// The function is expected to be executed and the likely() should pipeline /// that branch and make this device cheaper to use under normal circumstances. /// -struct ircd::util::unwind::nominal +template +struct ircd::util::unwind_nominal { - struct assertion; + F func; - const std::function func; - - template - nominal(F&& func) + unwind_nominal(F&& func) :func{std::forward(func)} {} - ~nominal() noexcept __attribute__((always_inline)) + ~unwind_nominal() noexcept __attribute__((always_inline)) { if(likely(!std::uncaught_exceptions())) func(); } - nominal(const nominal &) = delete; + unwind_nominal(const unwind_nominal &) = delete; }; /// Executes function only if unwind is taking place because exception thrown @@ -76,40 +77,38 @@ struct ircd::util::unwind::nominal /// optimize the pipeline for the nominal path, making this device as cheap /// as possible to use. /// -struct ircd::util::unwind::exceptional +template +struct ircd::util::unwind_exceptional { - struct assertion; + F func; - const std::function func; - - template - exceptional(F&& func) + unwind_exceptional(F&& func) :func{std::forward(func)} {} - ~exceptional() noexcept __attribute__((always_inline)) + ~unwind_exceptional() noexcept __attribute__((always_inline)) { if(unlikely(std::uncaught_exceptions())) func(); } - exceptional(const exceptional &) = delete; + unwind_exceptional(const unwind_exceptional &) = delete; }; /// Posts function to the event loop at the unwind rather than executing it /// as with nominal/exceptional. /// -struct ircd::util::unwind::defer +struct ircd::util::unwind_defer { std::function func; template - defer(F&& func) + unwind_defer(F&& func) :func{std::forward(func)} {} - defer(const defer &) = delete; - ~defer() noexcept; + unwind_defer(const unwind_defer &) = delete; + ~unwind_defer() noexcept; }; /// Asserts that unwind is occurring without any exception. This allows some @@ -118,9 +117,9 @@ struct ircd::util::unwind::defer /// exception is expected thus placing other guarantees should not be required /// if this guarantee is met. /// -struct ircd::util::unwind::nominal::assertion +struct ircd::util::unwind_nominal_assertion { - ~assertion() noexcept + ~unwind_nominal_assertion() noexcept { assert(likely(!std::uncaught_exceptions())); } @@ -129,9 +128,9 @@ struct ircd::util::unwind::nominal::assertion /// Complements exceptional::assertion. This triggers an assertion when /// unwinding WITHOUT an exception. /// -struct ircd::util::unwind::exceptional::assertion +struct ircd::util::unwind_exceptional_assertion { - ~assertion() noexcept + ~unwind_exceptional_assertion() noexcept { assert(likely(std::uncaught_exceptions())); } diff --git a/ircd/ctx.cc b/ircd/ctx.cc index d605c62e0..c4400f264 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -1264,7 +1264,7 @@ ircd::ctx::context::context(const string_view &name, // we expect the context to be committed to entry. If the POST flag is // supplied and it gets lost in the asio queue it will not be entered, and // will not be able to free itself; that will leak. - const unwind::nominal release{[this] + const unwind_nominal release{[this] { assert(c); if(c->flags & context::DETACH) @@ -2729,7 +2729,7 @@ void ircd::ctx::dock::wait() { assert(current); - const unwind::exceptional renotify{[this] + const unwind_exceptional renotify{[this] { notify_one(); }}; @@ -2750,7 +2750,7 @@ ircd::ctx::dock::wait(const predicate &pred) return; assert(current); - const unwind::exceptional renotify{[this] + const unwind_exceptional renotify{[this] { notify_one(); }}; diff --git a/ircd/ircd.cc b/ircd/ircd.cc index 19a239035..9277cd060 100644 --- a/ircd/ircd.cc +++ b/ircd/ircd.cc @@ -270,7 +270,7 @@ noexcept try // When this function completes without exception, subsystems are done shutting down and IRCd // transitions to HALT. - const unwind::defer halted{[] + const unwind_defer halted{[] { run::set(run::level::HALT); }}; diff --git a/ircd/net.cc b/ircd/net.cc index aedc0b47c..4990470c6 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -3153,7 +3153,7 @@ try assert(!fini); set_timeout(opts.timeout); - const unwind::exceptional unset{[this] + const unwind_exceptional unset{[this] { cancel_timeout(); }}; diff --git a/ircd/resource.cc b/ircd/resource.cc index 7c3749344..ec38dc1fd 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -529,7 +529,7 @@ try client.request.param, tokens(pathparm, '/', client.request.param) }; - const unwind::nominal completions{[this] + const unwind_nominal completions{[this] { ++stats->completions; }}; diff --git a/ircd/server.cc b/ircd/server.cc index 23757556b..36d65a2e3 100644 --- a/ircd/server.cc +++ b/ircd/server.cc @@ -1174,7 +1174,7 @@ try if(op_fini) return; - const unwind::exceptional failure{[this] + const unwind_exceptional failure{[this] { op_resolve = false; err_set(std::current_exception()); @@ -1850,7 +1850,7 @@ ircd::server::link::open(const net::open_opts &open_opts) op_init = true; op_open = true; - const unwind::exceptional unhandled{[this] + const unwind_exceptional unhandled{[this] { op_init = false; op_open = false; @@ -1938,7 +1938,7 @@ ircd::server::link::wait_writable() assert(ready()); op_write = true; - const unwind::exceptional unhandled{[this] + const unwind_exceptional unhandled{[this] { op_write = false; }}; @@ -2119,7 +2119,7 @@ ircd::server::link::wait_readable() assert(ready()); op_read = true; - const unwind::exceptional unhandled{[this] + const unwind_exceptional unhandled{[this] { op_read = false; }}; diff --git a/ircd/util.cc b/ircd/util.cc index 074442208..72dde6440 100644 --- a/ircd/util.cc +++ b/ircd/util.cc @@ -509,7 +509,7 @@ ircd::util::a2u(const mutable_buffer &out, // util/unwind.h // -ircd::util::unwind::defer::~defer() +ircd::util::unwind_defer::~unwind_defer() noexcept { ircd::defer diff --git a/matrix/matrix.cc b/matrix/matrix.cc index 69a6c5189..bedea5a2f 100644 --- a/matrix/matrix.cc +++ b/matrix/matrix.cc @@ -247,7 +247,7 @@ catch(const m::error &e) /* ircd::m::init::modules::modules() { - const unwind::exceptional unload{[this] + const unwind_exceptional unload{[this] { this->fini_imports(); }}; diff --git a/modules/federation/invite.cc b/modules/federation/invite.cc index b499e7719..69d7bd02d 100644 --- a/modules/federation/invite.cc +++ b/modules/federation/invite.cc @@ -161,7 +161,7 @@ put__invite(client &client, // We don't want this eval throwing an exception because the response has // already been made for this request. - const unwind::nominal::assertion na; + const unwind_nominal_assertion na; vmopts.nothrows = -1; m::vm::eval diff --git a/modules/federation/sender.cc b/modules/federation/sender.cc index d015e1214..a8d75f185 100644 --- a/modules/federation/sender.cc +++ b/modules/federation/sender.cc @@ -345,7 +345,7 @@ try }; txns.emplace_back(*this, std::move(content), std::move(opts)); - const unwind::nominal::assertion na; + const unwind_nominal_assertion na; curtxn = &txns.back(); q.clear(); log::debug diff --git a/modules/media/media.cc b/modules/media/media.cc index 2a5d72b9f..43cdde5d8 100644 --- a/modules/media/media.cc +++ b/modules/media/media.cc @@ -307,7 +307,7 @@ try }; create(room, user_id, "file"); - const unwind::exceptional purge{[&room] + const unwind_exceptional purge{[&room] { m::room::purge(room); }}; diff --git a/modules/web_root.cc b/modules/web_root.cc index cdf842402..b8cf3d56b 100644 --- a/modules/web_root.cc +++ b/modules/web_root.cc @@ -234,7 +234,7 @@ try file_size }; - const unwind::exceptional terminate{[&client] + const unwind_exceptional terminate{[&client] { client.close(net::dc::RST, net::close_ignore); }};