From 7af8e5774c356e3557fc7e14266e8fef1712cc49 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 5 Jul 2019 17:34:42 -0700 Subject: [PATCH] ircd::ios: Add no-op synchronous defer overload; use w/ this_ctx::yield(). --- include/ircd/ios.h | 3 +++ ircd/ctx.cc | 15 +++-------- ircd/ios.cc | 63 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/include/ircd/ios.h b/include/ircd/ios.h index 307abed20..5f490b732 100644 --- a/include/ircd/ios.h +++ b/include/ircd/ios.h @@ -77,6 +77,7 @@ struct ircd::ios::dispatch { dispatch(descriptor &, std::function); dispatch(descriptor &, synchronous_t, const std::function &); + dispatch(descriptor &, synchronous_t); dispatch(std::function); dispatch(synchronous_t, const std::function &); }; @@ -85,6 +86,7 @@ struct ircd::ios::defer { defer(descriptor &, std::function); defer(descriptor &, synchronous_t, const std::function &); + defer(descriptor &, synchronous_t); defer(std::function); defer(synchronous_t, const std::function &); }; @@ -93,6 +95,7 @@ struct ircd::ios::post { post(descriptor &, std::function); post(descriptor &, synchronous_t, const std::function &); + post(descriptor &, synchronous_t); post(std::function); post(synchronous_t, const std::function &); }; diff --git a/ircd/ctx.cc b/ircd/ctx.cc index 28e254d04..0c21295c2 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -638,19 +638,10 @@ ircd::ctx::this_ctx::yield() "ircd::ctx courtesy yield" }; - bool done(false); - const auto restore([&done, &me(cur())] + ircd::defer { - done = true; - notify(me); - }); - - // All spurious notifications are ignored until `done` - ircd::defer(descriptor, restore); do - { - wait(); - } - while(!done); + descriptor, ios::synchronous + }; } ulong diff --git a/ircd/ios.cc b/ircd/ios.cc index 1f904ca53..137017013 100644 --- a/ircd/ios.cc +++ b/ircd/ios.cc @@ -290,14 +290,31 @@ ircd::ios::dispatch_desc }; ircd::ios::dispatch::dispatch(std::function function) +:dispatch +{ + dispatch_desc, std::move(function) +} { - dispatch(dispatch_desc, std::move(function)); } ircd::ios::dispatch::dispatch(synchronous_t, const std::function &function) +:dispatch +{ + dispatch_desc, synchronous, std::move(function) +} +{ +} + +ircd::ios::dispatch::dispatch(descriptor &descriptor, + synchronous_t) +:dispatch +{ + dispatch_desc, synchronous, [] + { + } +} { - dispatch(dispatch_desc, synchronous, std::move(function)); } ircd::ios::dispatch::dispatch(descriptor &descriptor, @@ -337,14 +354,31 @@ ircd::ios::defer_desc }; ircd::ios::defer::defer(std::function function) +:defer +{ + defer_desc, std::move(function) +} { - defer(defer_desc, std::move(function)); } ircd::ios::defer::defer(synchronous_t, const std::function &function) +:defer +{ + defer_desc, synchronous, function +} +{ +} + +ircd::ios::defer::defer(descriptor &descriptor, + synchronous_t) +:defer +{ + defer_desc, synchronous, [] + { + } +} { - defer(defer_desc, synchronous, function); } ircd::ios::defer::defer(descriptor &descriptor, @@ -384,14 +418,31 @@ ircd::ios::post_desc }; ircd::ios::post::post(std::function function) +:post +{ + post_desc, std::move(function) +} { - post(post_desc, std::move(function)); } ircd::ios::post::post(synchronous_t, const std::function &function) +:post +{ + post_desc, synchronous, function +} +{ +} + +ircd::ios::post::post(descriptor &descriptor, + synchronous_t) +:post +{ + descriptor, synchronous, [] + { + } +} { - post(post_desc, synchronous, function); } ircd::ios::post::post(descriptor &descriptor,