0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 08:23:56 +01:00

ircd: Remove use of all unwind::exceptional and unwind::nominal devices.

This commit is contained in:
Jason Volk 2019-03-11 18:18:58 -07:00
parent 2956183db9
commit 4f243826c2
7 changed files with 88 additions and 89 deletions

View file

@ -49,15 +49,11 @@ class ircd::ctx::dock
template<class duration>
bool
ircd::ctx::dock::wait_for(const duration &dur)
try
{
static const duration zero(0);
assert(current);
const unwind::exceptional renotify{[this]
{
notify_one();
}};
const unwind remove{[this]
{
q.remove(current);
@ -66,12 +62,18 @@ ircd::ctx::dock::wait_for(const duration &dur)
q.push_back(current);
return ircd::ctx::wait<std::nothrow_t>(dur) > zero;
}
catch(...)
{
notify_one();
throw;
}
/// Returns true if predicate passed; false if timed out
template<class duration>
bool
ircd::ctx::dock::wait_for(const duration &dur,
const predicate &pred)
try
{
static const duration zero(0);
@ -79,11 +81,6 @@ ircd::ctx::dock::wait_for(const duration &dur,
return true;
assert(current);
const unwind::exceptional renotify{[this]
{
notify_one();
}};
const unwind remove{[this]
{
q.remove(current);
@ -104,18 +101,19 @@ ircd::ctx::dock::wait_for(const duration &dur,
}
while(1);
}
catch(...)
{
notify_one();
throw;
}
/// Returns true if notified; false if timed out
template<class time_point>
bool
ircd::ctx::dock::wait_until(time_point&& tp)
try
{
assert(current);
const unwind::exceptional renotify{[this]
{
notify_one();
}};
const unwind remove{[this]
{
q.remove(current);
@ -124,22 +122,23 @@ ircd::ctx::dock::wait_until(time_point&& tp)
q.push_back(current);
return !ircd::ctx::wait_until<std::nothrow_t>(tp);
}
catch(...)
{
notify_one();
throw;
}
/// Returns true if predicate passed; false if timed out
template<class time_point>
bool
ircd::ctx::dock::wait_until(time_point&& tp,
const predicate &pred)
try
{
if(pred())
return true;
assert(current);
const unwind::exceptional renotify{[this]
{
notify_one();
}};
const unwind remove{[this]
{
q.remove(current);
@ -160,3 +159,8 @@ ircd::ctx::dock::wait_until(time_point&& tp,
}
while(1);
}
catch(...)
{
notify_one();
throw;
}

View file

@ -1087,27 +1087,6 @@ ircd::ctx::context::context(const string_view &name,
// which is probably the same event-slice as event::CUR_ENTER and not as useful.
mark(prof::event::SPAWN);
// When the user passes the DETACH flag we want to release the unique_ptr
// of the ctx if and only if that ctx is committed to freeing itself. Our
// commitment ends at the 180 of this function. If no exception was thrown
// 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, &flags]
{
if(flags & context::DETACH)
this->detach();
}
};
if(flags & POST)
{
ios::post(std::move(spawn));
return;
}
// The current context must be reasserted if spawn returns here
auto *const theirs(ircd::ctx::current);
const unwind recurrent([&theirs]
@ -1115,10 +1094,21 @@ ircd::ctx::context::context(const string_view &name,
ircd::ctx::current = theirs;
});
if(flags & DISPATCH)
if(flags & POST)
ios::post(std::move(spawn));
else if(flags & DISPATCH)
ios::dispatch(std::move(spawn));
else
spawn();
// When the user passes the DETACH flag we want to release the unique_ptr
// of the ctx if and only if that ctx is committed to freeing itself. Our
// commitment ends at the 180 of this function. If no exception was thrown
// 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.
if(flags & context::DETACH)
this->detach();
}
ircd::ctx::context::context(const string_view &name,
@ -2417,13 +2407,9 @@ noexcept
void
ircd::ctx::dock::wait()
try
{
assert(current);
const unwind::exceptional renotify{[this]
{
notify_one();
}};
const unwind remove{[this]
{
q.remove(current);
@ -2432,19 +2418,20 @@ ircd::ctx::dock::wait()
q.push_back(current);
ircd::ctx::wait();
}
catch(...)
{
notify_one();
throw;
}
void
ircd::ctx::dock::wait(const predicate &pred)
try
{
if(pred())
return;
assert(current);
const unwind::exceptional renotify{[this]
{
notify_one();
}};
const unwind remove{[this]
{
q.remove(current);
@ -2456,6 +2443,11 @@ ircd::ctx::dock::wait(const predicate &pred)
}
while(!pred());
}
catch(...)
{
notify_one();
throw;
}
void
ircd::ctx::dock::notify(ctx &ctx)

View file

@ -2251,11 +2251,6 @@ ircd::net::socket::wait(const wait_opts &opts,
try
{
set_timeout(opts.timeout);
const unwind::exceptional unset{[this]
{
cancel_timeout();
}};
switch(opts.type)
{
case ready::ERROR:
@ -2322,8 +2317,14 @@ try
}
catch(const boost::system::system_error &e)
{
cancel_timeout();
throw_system_error(e);
}
catch(...)
{
cancel_timeout();
throw;
}
void
ircd::net::socket::handle_ready(const std::weak_ptr<socket> wp,

View file

@ -1297,6 +1297,7 @@ ircd::server::link::cancel_uncommitted(std::exception_ptr eptr)
bool
ircd::server::link::open(const net::open_opts &open_opts)
try
{
assert(ircd::run::level == ircd::run::level::RUN);
@ -1309,14 +1310,14 @@ ircd::server::link::open(const net::open_opts &open_opts)
};
op_init = true;
const unwind::exceptional unhandled{[this]
{
op_init = false;
}};
socket = net::open(open_opts, std::move(handler));
return true;
}
catch(...)
{
op_init = false;
throw;
}
void
ircd::server::link::handle_open(std::exception_ptr eptr)
@ -1375,6 +1376,7 @@ ircd::server::link::handle_close(std::exception_ptr eptr)
void
ircd::server::link::wait_writable()
try
{
if(op_write || unlikely(op_fini))
return;
@ -1386,13 +1388,13 @@ ircd::server::link::wait_writable()
assert(ready());
op_write = true;
const unwind::exceptional unhandled{[this]
{
op_write = false;
}};
net::wait(*socket, net::ready::WRITE, std::move(handler));
}
catch(...)
{
op_write = false;
throw;
}
void
ircd::server::link::handle_writable(const error_code &ec)
@ -1545,17 +1547,13 @@ ircd::server::link::process_write_next(const const_buffer &buffer)
void
ircd::server::link::wait_readable()
try
{
if(op_read || op_fini)
return;
assert(ready());
op_read = true;
const unwind::exceptional unhandled{[this]
{
op_read = false;
}};
auto handler
{
std::bind(&link::handle_readable, this, ph::_1)
@ -1563,6 +1561,11 @@ ircd::server::link::wait_readable()
net::wait(*socket, net::ready::READ, std::move(handler));
}
catch(...)
{
op_read = false;
throw;
}
void
ircd::server::link::handle_readable(const error_code &ec)

View file

@ -264,7 +264,6 @@ try
};
txns.emplace_back(*this, std::move(content), std::move(opts));
const unwind::nominal::assertion na;
curtxn = &txns.back();
q.clear();
recv_action.notify_one();

View file

@ -166,7 +166,6 @@ ircd::net::dns::resolver::sendq_work()
assert(!sendq.empty());
assert(sendq.size() < 65535);
assert(sendq.size() <= tags.size());
const unwind::nominal::assertion na;
const uint16_t next(sendq.front());
sendq.pop_front();
flush(next);
@ -335,19 +334,16 @@ ircd::net::dns::resolver::operator()(const hostport &hp,
const opts &opts,
callback &&callback)
{
auto &tag
auto &tag(set_tag(hp, opts, std::move(callback))); try
{
set_tag(hp, opts, std::move(callback))
};
// Escape trunk
const unwind::exceptional untag{[this, &tag]
tag.question = make_query(tag.qbuf, tag);
submit(tag);
}
catch(...)
{
remove(tag);
}};
tag.question = make_query(tag.qbuf, tag);
submit(tag);
throw;
}
}
ircd::const_buffer

View file

@ -194,11 +194,6 @@ try
file_size
};
const unwind::exceptional terminate{[&client]
{
client.close(net::dc::RST, net::close_ignore);
}};
size_t written
{
client.write_all(chunk)
@ -233,6 +228,15 @@ catch(const fs::error &e)
"%s", e.what()
};
}
catch(const http::error &)
{
throw;
}
catch(...)
{
client.close(net::dc::RST, net::close_ignore);
throw;
}
string_view
content_type(const mutable_buffer &out,