0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-26 18:38:52 +02:00

ircd: Rename ircd::scope to ircd::unwind.

This commit is contained in:
Jason Volk 2017-09-22 13:57:43 -07:00
parent b7e1b3cf43
commit b207b9e909
12 changed files with 74 additions and 51 deletions

View file

@ -135,7 +135,7 @@ try
{
using namespace ircd;
const scope atexit([]
const unwind atexit([]
{
console_active = false;
console_in = nullptr;

View file

@ -118,7 +118,7 @@ noexcept
inline void
ircd::ctx::dock::wait()
{
const scope remove
const unwind remove
{
std::bind(&dock::remove_self, this)
};
@ -134,7 +134,7 @@ ircd::ctx::dock::wait(predicate&& pred)
if(pred())
return;
const scope remove
const unwind remove
{
std::bind(&dock::remove_self, this)
};
@ -152,7 +152,7 @@ ircd::ctx::dock::wait_for(const duration &dur)
{
static const duration zero(0);
const scope remove
const unwind remove
{
std::bind(&dock::remove_self, this)
};
@ -173,7 +173,7 @@ ircd::ctx::dock::wait_for(const duration &dur,
if(pred())
return true;
const scope remove
const unwind remove
{
std::bind(&dock::remove_self, this)
};
@ -195,7 +195,7 @@ template<class time_point>
ircd::ctx::cv_status
ircd::ctx::dock::wait_until(time_point&& tp)
{
const scope remove
const unwind remove
{
std::bind(&dock::remove_self, this)
};
@ -214,7 +214,7 @@ ircd::ctx::dock::wait_until(time_point&& tp,
if(pred())
return true;
const scope remove
const unwind remove
{
std::bind(&dock::remove_self, this)
};

View file

@ -93,7 +93,7 @@ ircd::ctx::queue<T>::pop()
return !q.empty();
});
const scope pop([this]
const unwind pop([this]
{
q.pop();
});
@ -115,7 +115,7 @@ ircd::ctx::queue<T>::pop_for(const duration &dur)
if(status == cv_status::timeout)
throw timeout();
const scope pop([this]
const unwind pop([this]
{
q.pop();
});
@ -137,7 +137,7 @@ ircd::ctx::queue<T>::pop_until(time_point&& tp)
if(status == cv_status::timeout)
throw timeout();
const scope pop([this]
const unwind pop([this]
{
q.pop();
});

View file

@ -80,7 +80,7 @@ template<class T>
void
ircd::ctx::view<T>::notify(T &t)
{
const scope afterward{[this]
const unwind afterward{[this]
{
assert(a.empty());
this->t = nullptr;

View file

@ -184,7 +184,7 @@ run(F&& function)
assert(!pending_exception(*cx));
enter(*cx);
const scope out([]
const unwind out([]
{
leave(*cx);
});

View file

@ -79,7 +79,14 @@ enum class init_priority
#define IRCD_INIT_PRIORITY(name) \
__attribute__((init_priority(int(ircd::init_priority::name))))
struct scope
///
/// Fundamental scope-unwind utilities establishing actions during destruction
///
/// Unconditionally executes the provided code when the object goes out of scope.
///
struct unwind
{
struct nominal;
struct exceptional;
@ -87,48 +94,64 @@ struct scope
const std::function<void ()> func;
template<class F>
scope(F &&func): func(std::forward<F>(func)) {}
scope() = default;
scope(const scope &) = delete;
scope &operator=(const scope &) = delete;
~scope() noexcept
unwind(F &&func)
:func{std::forward<F>(func)}
{}
unwind(const unwind &) = delete;
unwind &operator=(const unwind &) = delete;
~unwind() noexcept
{
func();
}
};
struct scope::nominal
:scope
/// Executes function only if the unwind takes place without active exception
///
/// 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 unwind::nominal
{
const std::function<void ()> func;
template<class F>
nominal(F &&func)
:scope
{
[func(std::forward<F>(func))]
:func{std::forward<F>(func)}
{}
~nominal() noexcept
{
if(likely(!std::uncaught_exception()))
func();
}
}{}
nominal() = default;
nominal(const nominal &) = delete;
};
struct scope::exceptional
:scope
/// Executes function only if unwind is taking place because exception thrown
///
/// The unlikely() intends for the cost of a branch misprediction to be paid
/// for fetching and executing this function. This is because we strive to
/// optimize the pipeline for the nominal path, making this device as cheap
/// as possible to use.
///
struct unwind::exceptional
{
const std::function<void ()> func;
template<class F>
exceptional(F &&func)
:scope
{
[func(std::forward<F>(func))]
:func{std::forward<F>(func)}
{}
~exceptional() noexcept
{
if(unlikely(std::uncaught_exception()))
func();
}
}{}
exceptional() = default;
exceptional(const exceptional &) = delete;
};

View file

@ -101,7 +101,7 @@ noexcept
ircd::ctx::current = this;
mark(prof::event::CUR_ENTER);
const scope atexit([this]
const unwind atexit([this]
{
mark(prof::event::CUR_LEAVE);
@ -428,7 +428,7 @@ ircd::ctx::context::context(const char *const &name,
});
// The current context must be reasserted if spawn returns here
const scope recurrent([current(ircd::ctx::current)]
const unwind recurrent([current(ircd::ctx::current)]
{
ircd::ctx::current = current;
});
@ -584,7 +584,7 @@ ircd::ctx::pool::main()
try
{
++available;
const scope avail([this]
const unwind avail([this]
{
--available;
});
@ -610,7 +610,7 @@ try
});
--available;
const scope avail([this]
const unwind avail([this]
{
++available;
});

View file

@ -260,7 +260,7 @@ try
{
const head h{pc, headers_closure};
const char *const content_mark(pc.parsed);
const scope discard_unused_content{[&pc, &h, &content_mark]
const unwind discard_unused_content{[&pc, &h, &content_mark]
{
const size_t consumed(pc.parsed - content_mark);
const size_t remain(h.content_length - consumed);
@ -369,7 +369,7 @@ ircd::http::response::response(parse::capstan &pc,
{
const head h{pc, headers_closure};
const char *const content_mark(pc.parsed);
const scope discard_unused_content{[&pc, &h, &content_mark]
const unwind discard_unused_content{[&pc, &h, &content_mark]
{
const size_t consumed(pc.parsed - content_mark);
const size_t remain(h.content_length - consumed);

View file

@ -99,7 +99,7 @@ ircd::main()
try
{
log::debug("IRCd entered main context.");
const scope main_exit(&main_exiting); // The user is notified when this function ends
const unwind main_exit(&main_exiting); // The user is notified when this function ends
// These objects are the init()'s and fini()'s for each subsystem. Appearing here ties their life
// to the main context. Initialization can also occur in ircd::init() or static initialization

View file

@ -72,7 +72,7 @@ ircd::js::init::init()
"SpiderMonkey",
version(ver::IMPLEMENTATION));
const scope exit([this]
const unwind exit([this]
{
// Ensure ~init() is always safe to call at any intermediate state
if(std::current_exception())
@ -3348,7 +3348,7 @@ noexcept
// After the interrupt is handled the phase indicates entry back to JS,
// IRQ is left indicating JS in case we don't trigger the next interrupt.
const scope interrupt_return([&c, &state]
const unwind interrupt_return([&c, &state]
{
state.phase = phase::ENTER;
state.irq = irq::JS;

View file

@ -274,7 +274,7 @@ ircd::log::slog(const facility &fac,
if(!file[fac].is_open() && !console_out[fac] && !console_err[fac])
return;
const scope always_newline([&fac]
const unwind always_newline([&fac]
{
suffix(fac);
});

View file

@ -650,7 +650,7 @@ try
}
});
const scope reset{[this, &theirs]
const unwind reset{[this, &theirs]
{
assert(loading.top() == this);
loading.pop();