mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
ircd: Replace various unwind count patterns with scope_count.
This commit is contained in:
parent
8054317106
commit
af6ac4a2ac
8 changed files with 56 additions and 65 deletions
|
@ -102,11 +102,10 @@ template<class T,
|
|||
T
|
||||
ircd::ctx::queue<T, A>::pop()
|
||||
{
|
||||
++w;
|
||||
const unwind uw{[this]
|
||||
const scope_count w
|
||||
{
|
||||
--w;
|
||||
}};
|
||||
this->w
|
||||
};
|
||||
|
||||
d.wait([this]
|
||||
{
|
||||
|
@ -125,11 +124,10 @@ template<class duration>
|
|||
T
|
||||
ircd::ctx::queue<T, A>::pop_for(const duration &dur)
|
||||
{
|
||||
++w;
|
||||
const unwind uw{[this]
|
||||
const scope_count w
|
||||
{
|
||||
--w;
|
||||
}};
|
||||
this->w
|
||||
};
|
||||
|
||||
const bool ready
|
||||
{
|
||||
|
@ -154,11 +152,10 @@ template<class time_point>
|
|||
T
|
||||
ircd::ctx::queue<T, A>::pop_until(time_point&& tp)
|
||||
{
|
||||
++w;
|
||||
const unwind uw{[this]
|
||||
const scope_count w
|
||||
{
|
||||
--w;
|
||||
}};
|
||||
this->w
|
||||
};
|
||||
|
||||
const bool ready
|
||||
{
|
||||
|
|
16
ircd/ctx.cc
16
ircd/ctx.cc
|
@ -1391,13 +1391,12 @@ void
|
|||
ircd::ctx::pool::main()
|
||||
noexcept try
|
||||
{
|
||||
++running;
|
||||
q_max.notify();
|
||||
const unwind avail([this]
|
||||
const scope_count running
|
||||
{
|
||||
--running;
|
||||
});
|
||||
this->running
|
||||
};
|
||||
|
||||
q_max.notify();
|
||||
while(!termination(cur()))
|
||||
work();
|
||||
}
|
||||
|
@ -1425,10 +1424,13 @@ try
|
|||
std::move(q.pop())
|
||||
};
|
||||
|
||||
++working;
|
||||
const scope_count working
|
||||
{
|
||||
this->working
|
||||
};
|
||||
|
||||
const unwind avail([this]
|
||||
{
|
||||
--working;
|
||||
q_max.notify();
|
||||
});
|
||||
|
||||
|
|
|
@ -173,12 +173,8 @@ ircd::fs::aio::read(const fd &fd,
|
|||
fd, bufs, opts
|
||||
};
|
||||
|
||||
stats.cur_reads++;
|
||||
const scope_count cur_reads{stats.cur_reads};
|
||||
stats.max_reads = std::max(stats.max_reads, stats.cur_reads);
|
||||
const unwind dec{[]
|
||||
{
|
||||
stats.cur_reads--;
|
||||
}};
|
||||
|
||||
// Make request; blocks ircd::ctx until completed or throw.
|
||||
const size_t bytes
|
||||
|
@ -225,13 +221,15 @@ ircd::fs::aio::write(const fd &fd,
|
|||
};
|
||||
#endif
|
||||
|
||||
stats.cur_bytes_write += req_bytes;
|
||||
stats.cur_writes++;
|
||||
// track current write count
|
||||
const scope_count cur_writes{stats.cur_writes};
|
||||
stats.max_writes = std::max(stats.max_writes, stats.cur_writes);
|
||||
|
||||
// track current write bytes count
|
||||
stats.cur_bytes_write += req_bytes;
|
||||
const unwind dec{[&req_bytes]
|
||||
{
|
||||
stats.cur_bytes_write -= req_bytes;
|
||||
stats.cur_writes--;
|
||||
}};
|
||||
|
||||
// Make the request; ircd::ctx blocks here. Throws on error
|
||||
|
|
16
ircd/json.cc
16
ircd/json.cc
|
@ -2188,13 +2188,9 @@ try
|
|||
|
||||
thread_local member_arrays ma;
|
||||
thread_local size_t mctr;
|
||||
const size_t mc{mctr++};
|
||||
const size_t mc{mctr};
|
||||
const scope_count _mc{mctr};
|
||||
assert(mc < ma.size());
|
||||
const unwind uw{[&mc]
|
||||
{
|
||||
--mctr;
|
||||
assert(mctr == mc);
|
||||
}};
|
||||
|
||||
size_t i(0);
|
||||
auto &m{ma.at(mc)};
|
||||
|
@ -2932,13 +2928,9 @@ try
|
|||
|
||||
thread_local member_arrays ma;
|
||||
thread_local size_t mctr;
|
||||
const size_t mc{mctr++};
|
||||
const size_t mc{mctr};
|
||||
const scope_count _mc{mctr};
|
||||
assert(mc < ma.size());
|
||||
const unwind uw{[&mc]
|
||||
{
|
||||
--mctr;
|
||||
assert(mctr == mc);
|
||||
}};
|
||||
|
||||
size_t i(0);
|
||||
auto &m{ma.at(mc)};
|
||||
|
|
|
@ -311,11 +311,10 @@ ircd::m::state::_dfs_recurse(const search_closure &closure,
|
|||
const json::array &key,
|
||||
int &depth)
|
||||
{
|
||||
++depth;
|
||||
const unwind down{[&depth]
|
||||
const scope_count down
|
||||
{
|
||||
--depth;
|
||||
}};
|
||||
depth
|
||||
};
|
||||
|
||||
const node::rep rep{node};
|
||||
const auto kpos{rep.find(key)};
|
||||
|
@ -458,9 +457,12 @@ ircd::m::state::_insert(int8_t &height,
|
|||
node::rep &push)
|
||||
{
|
||||
// Recursion metrics
|
||||
const unwind down{[&height]{ --height; }};
|
||||
if(unlikely(++height >= MAX_HEIGHT))
|
||||
throw panic{"recursion limit exceeded"};
|
||||
const scope_count down{height};
|
||||
if(unlikely(height >= MAX_HEIGHT))
|
||||
throw panic
|
||||
{
|
||||
"recursion limit exceeded"
|
||||
};
|
||||
|
||||
// This function assumes that any node argument is a previously "existing"
|
||||
// node which means it contains at least one key/value.
|
||||
|
@ -748,9 +750,12 @@ ircd::m::state::_remove(int8_t &height,
|
|||
const mutable_buffer &idbuf,
|
||||
node::rep &push)
|
||||
{
|
||||
const unwind down{[&height]{ --height; }};
|
||||
if(unlikely(++height >= MAX_HEIGHT))
|
||||
throw panic{"recursion limit exceeded"};
|
||||
const scope_count down{height};
|
||||
if(unlikely(height >= MAX_HEIGHT))
|
||||
throw panic
|
||||
{
|
||||
"recursion limit exceeded"
|
||||
};
|
||||
|
||||
node::rep rep{node};
|
||||
const auto pos{node.find(key)};
|
||||
|
|
|
@ -1767,11 +1767,10 @@ ircd::net::listener_udp::acceptor::operator()(datagram &datagram)
|
|||
this->interrupt();
|
||||
}};
|
||||
|
||||
this->waiting++;
|
||||
const unwind dec{[this]
|
||||
const scope_count waiting
|
||||
{
|
||||
this->waiting--;
|
||||
}};
|
||||
this->waiting
|
||||
};
|
||||
|
||||
ip::udp::endpoint ep;
|
||||
size_t rlen; continuation
|
||||
|
|
|
@ -302,15 +302,18 @@ ircd::resource::method::operator()(client &client,
|
|||
const string_view &content_partial)
|
||||
try
|
||||
{
|
||||
++stats->requests;
|
||||
++stats->pending;
|
||||
const unwind dec_pending{[this]
|
||||
const unwind on_idle{[this]
|
||||
{
|
||||
assert(stats->pending > 0);
|
||||
if(--stats->pending == 0)
|
||||
if(stats->pending == 0)
|
||||
idle_dock.notify_all();
|
||||
}};
|
||||
|
||||
++stats->requests;
|
||||
const scope_count pending
|
||||
{
|
||||
stats->pending
|
||||
};
|
||||
|
||||
// Bail out if the method limited the amount of content and it was exceeded.
|
||||
if(head.content_length > opts->payload_max)
|
||||
throw http::error
|
||||
|
|
|
@ -517,12 +517,7 @@ ircd::m::sync::longpoll::poll(data &data,
|
|||
const args &args)
|
||||
try
|
||||
{
|
||||
const unwind unpoll{[]
|
||||
{
|
||||
--polling;
|
||||
}};
|
||||
|
||||
++polling; do
|
||||
const scope_count polling{longpoll::polling}; do
|
||||
{
|
||||
if(!dock.wait_until(args.timesout))
|
||||
break;
|
||||
|
@ -537,7 +532,7 @@ try
|
|||
|
||||
const unwind pop{[]
|
||||
{
|
||||
if(polling <= 1)
|
||||
if(longpoll::polling <= 1)
|
||||
queue.pop_front();
|
||||
}};
|
||||
|
||||
|
|
Loading…
Reference in a new issue