Skip to content

Commit

Permalink
Add CLockFreeGuard before get method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed May 18, 2022
1 parent 3257ece commit 77cd761
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/rpc/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ RPCStats RPCStats::fromJSON(UniValue json) {

void CRPCStats::add(const std::string& name, const int64_t latency, const int64_t payload)
{
CLockFreeGuard lock(lock_stats);
auto stats = CRPCStats::get(name);
if (stats) {
stats->count++;
Expand All @@ -93,8 +94,6 @@ void CRPCStats::add(const std::string& name, const int64_t latency, const int64_
stats = { name, latency, payload };
}
stats->history.push_back({ stats->lastUsedTime, latency, payload });

CLockFreeGuard lock(lock_stats);
map[name] = *stats;
}

Expand Down Expand Up @@ -143,6 +142,9 @@ static UniValue getrpcstats(const JSONRPCRequest& request)
}

auto command = request.params[0].get_str();

CLockFreeGuard lock(lock_stats);

auto stats = statsRPC.get(command);
if (!stats) {
throw JSONRPCError(RPC_INVALID_PARAMS, "No stats for this command.");
Expand Down

0 comments on commit 77cd761

Please sign in to comment.