0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-24 14:34:00 +01:00

ircd: Apply branch expectation attributes to various case labels.

This commit is contained in:
Jason Volk 2023-02-01 21:48:28 -08:00
parent 5e32f88b0d
commit 89e44ce8e9
8 changed files with 38 additions and 4 deletions

View file

@ -56,12 +56,15 @@ ircd::allocator::allocate(const size_t alignment,
void *ret;
switch(int errc(::posix_memalign(&ret, alignment, size)); errc)
{
[[likely]]
case 0:
break;
[[unlikely]]
case int(std::errc::not_enough_memory):
throw std::bad_alloc{};
[[unlikely]]
default:
throw_system_error();
__builtin_unreachable();
@ -249,9 +252,11 @@ ircd::allocator::advise(const const_buffer &buf,
assert(aligned(data(buf), info::page_size));
switch(const auto r(::madvise(mutable_cast(data(buf)), size(buf), advice)); r)
{
[[likely]]
case 0:
return size(buf); // success
[[unlikely]]
default:
throw_system_error(r); // error
}

View file

@ -4398,6 +4398,7 @@ ircd::db::throw_on_error::throw_on_error(const rocksdb::Status &status)
switch(status.code())
{
[[likely]]
case Status::kOk:
return;
@ -4412,6 +4413,7 @@ ircd::db::throw_on_error::throw_on_error(const rocksdb::Status &status)
[[fallthrough]];
#endif
[[unlikely]]
default:
throw error
{
@ -4444,6 +4446,7 @@ ircd::db::error_to_status::error_to_status(const std::error_code &e)
switch(e.value())
{
[[likely]]
case 0:
return Status::OK();
@ -4529,6 +4532,7 @@ ircd::db::append(rocksdb::WriteBatch &batch,
const auto v(slice(std::get<2>(delta)));
switch(std::get<0>(delta))
{
[[unlikely]]
case op::GET: assert(0); break;
case op::SET: batch.Put(c, k, v); break;
case op::MERGE: batch.Merge(c, k, v); break;
@ -5120,11 +5124,13 @@ ircd::db::valid(const rocksdb::Iterator &it)
{
using rocksdb::Status;
[[likely]]
case Status::kOk:
case Status::kNotFound:
case Status::kIncomplete:
return it.Valid();
[[unlikely]]
default:
throw_on_error
{
@ -5142,13 +5148,16 @@ ircd::db::valid(const rocksdb::Status &s)
{
using rocksdb::Status;
[[likely]]
case Status::kOk:
return true;
[[likely]]
case Status::kNotFound:
case Status::kIncomplete:
return false;
[[unlikely]]
default:
throw_on_error{s};
__builtin_unreachable();

View file

@ -523,7 +523,7 @@ ircd::db::loglevel(const database &d)
switch(level)
{
default:
[[unlikely]]
case rocksdb::NUM_INFO_LOG_LEVELS:
assert(0);
@ -534,6 +534,9 @@ ircd::db::loglevel(const database &d)
case rocksdb::INFO_LEVEL: return log::level::INFO;
case rocksdb::DEBUG_LEVEL: return log::level::DEBUG;
}
assert(0);
__builtin_unreachable();
}
ircd::db::options

View file

@ -2332,8 +2332,13 @@ ircd::fs::advise(const fd &fd,
cnt = std::min(opts.offset + count - off, max_count);
switch(const auto r(::posix_fadvise(fd, off, cnt, advice)); r)
{
case 0: break;
default: throw_system_error(r);
[[likely]]
case 0:
break;
[[unlikely]]
default:
throw_system_error(r);
}
}
while(off + cnt < opts.offset + count);

View file

@ -1671,6 +1671,7 @@ try
};
break;
[[unlikely]]
default:
throw ircd::not_implemented{};
}
@ -1760,7 +1761,9 @@ try
return;
}
default: throw ircd::not_implemented{};
[[unlikely]]
default:
throw ircd::not_implemented{};
}
}
catch(const boost::system::system_error &e)
@ -2188,6 +2191,7 @@ noexcept try
}
// A cancelation means there was no timeout.
[[likely]]
case int(std::errc::operation_canceled):
{
assert(ec.category() == std::system_category());
@ -2196,6 +2200,7 @@ noexcept try
}
// All other errors are unexpected, logged and ignored here.
[[unlikely]]
default: throw panic
{
"socket(%p): unexpected :%s",
@ -2520,6 +2525,7 @@ noexcept try
if(!valid) switch(err)
{
[[unlikely]]
case X509_V_OK:
assert(0);

View file

@ -172,6 +172,7 @@ ircd::net::dns::resolver::make_query(const mutable_buffer &buf,
string_view hoststr;
switch(tag.opts.qtype)
{
[[unlikely]]
case 0: throw error
{
"Query type is required to form a question."
@ -803,6 +804,7 @@ ircd::net::dns::resolver::handle_error(const header &header,
{
switch(header.rcode)
{
[[likely]]
case 0: // NoError; continue
return true;

View file

@ -1117,6 +1117,7 @@ try
return;
}
[[unlikely]]
default: throw http::error
{
"Cannot send json::%s as response content",

View file

@ -1236,6 +1236,7 @@ ircd::server::peer::handle_error(link &link,
if(system_category(ec)) switch(ec.value())
{
[[unlikely]]
case 0:
assert(0);
break;
@ -2414,6 +2415,7 @@ noexcept try
if(system_category(ec)) switch(ec.value())
{
[[likely]]
case 0:
handle_writable_success();
return;
@ -2601,6 +2603,7 @@ noexcept try
if(system_category(ec)) switch(ec.value())
{
[[likely]]
case 0:
handle_readable_success();
return;