mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 18:22:50 +01:00
ircd::util: Add an unwind::defer device.
This commit is contained in:
parent
5232893c6a
commit
c6a59ab6b1
2 changed files with 31 additions and 0 deletions
|
@ -24,6 +24,7 @@ namespace ircd::util
|
||||||
///
|
///
|
||||||
struct ircd::util::unwind
|
struct ircd::util::unwind
|
||||||
{
|
{
|
||||||
|
struct defer;
|
||||||
struct nominal;
|
struct nominal;
|
||||||
struct exceptional;
|
struct exceptional;
|
||||||
|
|
||||||
|
@ -94,6 +95,22 @@ struct ircd::util::unwind::exceptional
|
||||||
exceptional(const exceptional &) = delete;
|
exceptional(const exceptional &) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Posts function to the event loop at the unwind rather than executing it
|
||||||
|
/// as with nominal/exceptional.
|
||||||
|
///
|
||||||
|
struct ircd::util::unwind::defer
|
||||||
|
{
|
||||||
|
std::function<void ()> func;
|
||||||
|
|
||||||
|
template<class F>
|
||||||
|
defer(F&& func)
|
||||||
|
:func{std::forward<F>(func)}
|
||||||
|
{}
|
||||||
|
|
||||||
|
defer(const defer &) = delete;
|
||||||
|
~defer() noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
/// Asserts that unwind is occurring without any exception. This allows some
|
/// Asserts that unwind is occurring without any exception. This allows some
|
||||||
/// section of code, for example, the latter half of a function, to assert that
|
/// section of code, for example, the latter half of a function, to assert that
|
||||||
/// it is not throwing and disrupting the other half. This is useful when no
|
/// it is not throwing and disrupting the other half. This is useful when no
|
||||||
|
|
14
ircd/util.cc
14
ircd/util.cc
|
@ -582,6 +582,20 @@ ircd::util::a2u(const mutable_buffer &out,
|
||||||
return { data(out), len };
|
return { data(out), len };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// util/unwind.h
|
||||||
|
//
|
||||||
|
|
||||||
|
ircd::util::unwind::defer::~defer()
|
||||||
|
noexcept
|
||||||
|
{
|
||||||
|
ircd::defer
|
||||||
|
{
|
||||||
|
std::move(func)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// util/what.h
|
// util/what.h
|
||||||
|
|
Loading…
Reference in a new issue