0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01:00

ircd::ios: Add no-op synchronous defer overload; use w/ this_ctx::yield().

This commit is contained in:
Jason Volk 2019-07-05 17:34:42 -07:00
parent f48182404f
commit 7af8e5774c
3 changed files with 63 additions and 18 deletions

View file

@ -77,6 +77,7 @@ struct ircd::ios::dispatch
{ {
dispatch(descriptor &, std::function<void ()>); dispatch(descriptor &, std::function<void ()>);
dispatch(descriptor &, synchronous_t, const std::function<void ()> &); dispatch(descriptor &, synchronous_t, const std::function<void ()> &);
dispatch(descriptor &, synchronous_t);
dispatch(std::function<void ()>); dispatch(std::function<void ()>);
dispatch(synchronous_t, const std::function<void ()> &); dispatch(synchronous_t, const std::function<void ()> &);
}; };
@ -85,6 +86,7 @@ struct ircd::ios::defer
{ {
defer(descriptor &, std::function<void ()>); defer(descriptor &, std::function<void ()>);
defer(descriptor &, synchronous_t, const std::function<void ()> &); defer(descriptor &, synchronous_t, const std::function<void ()> &);
defer(descriptor &, synchronous_t);
defer(std::function<void ()>); defer(std::function<void ()>);
defer(synchronous_t, const std::function<void ()> &); defer(synchronous_t, const std::function<void ()> &);
}; };
@ -93,6 +95,7 @@ struct ircd::ios::post
{ {
post(descriptor &, std::function<void ()>); post(descriptor &, std::function<void ()>);
post(descriptor &, synchronous_t, const std::function<void ()> &); post(descriptor &, synchronous_t, const std::function<void ()> &);
post(descriptor &, synchronous_t);
post(std::function<void ()>); post(std::function<void ()>);
post(synchronous_t, const std::function<void ()> &); post(synchronous_t, const std::function<void ()> &);
}; };

View file

@ -638,19 +638,10 @@ ircd::ctx::this_ctx::yield()
"ircd::ctx courtesy yield" "ircd::ctx courtesy yield"
}; };
bool done(false); ircd::defer
const auto restore([&done, &me(cur())]
{ {
done = true; descriptor, ios::synchronous
notify(me); };
});
// All spurious notifications are ignored until `done`
ircd::defer(descriptor, restore); do
{
wait();
}
while(!done);
} }
ulong ulong

View file

@ -290,14 +290,31 @@ ircd::ios::dispatch_desc
}; };
ircd::ios::dispatch::dispatch(std::function<void ()> function) ircd::ios::dispatch::dispatch(std::function<void ()> function)
:dispatch
{
dispatch_desc, std::move(function)
}
{ {
dispatch(dispatch_desc, std::move(function));
} }
ircd::ios::dispatch::dispatch(synchronous_t, ircd::ios::dispatch::dispatch(synchronous_t,
const std::function<void ()> &function) const std::function<void ()> &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, ircd::ios::dispatch::dispatch(descriptor &descriptor,
@ -337,14 +354,31 @@ ircd::ios::defer_desc
}; };
ircd::ios::defer::defer(std::function<void ()> function) ircd::ios::defer::defer(std::function<void ()> function)
:defer
{
defer_desc, std::move(function)
}
{ {
defer(defer_desc, std::move(function));
} }
ircd::ios::defer::defer(synchronous_t, ircd::ios::defer::defer(synchronous_t,
const std::function<void ()> &function) const std::function<void ()> &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, ircd::ios::defer::defer(descriptor &descriptor,
@ -384,14 +418,31 @@ ircd::ios::post_desc
}; };
ircd::ios::post::post(std::function<void ()> function) ircd::ios::post::post(std::function<void ()> function)
:post
{
post_desc, std::move(function)
}
{ {
post(post_desc, std::move(function));
} }
ircd::ios::post::post(synchronous_t, ircd::ios::post::post(synchronous_t,
const std::function<void ()> &function) const std::function<void ()> &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, ircd::ios::post::post(descriptor &descriptor,