MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / addCost

Method addCost

include/common/statistics.h:85–99  ·  view source on GitHub ↗

Add cost and return false if the limit is exceeded.

Source from the content-addressed store, hash-verified

83
84 /// Add cost and return false if the limit is exceeded.
85 bool addCost(uint64_t Cost) {
86 using namespace std::literals;
87 const auto Limit = CostLimit;
88 uint64_t OldCostSum = CostSum.load(std::memory_order_relaxed);
89 uint64_t NewCostSum;
90 do {
91 NewCostSum = OldCostSum + Cost;
92 if (unlikely(NewCostSum > Limit)) {
93 spdlog::error("Cost exceeded limit. Force terminate the execution."sv);
94 return false;
95 }
96 } while (!CostSum.compare_exchange_weak(OldCostSum, NewCostSum,
97 std::memory_order_relaxed));
98 return true;
99 }
100
101 /// Return cost back.
102 bool subCost(uint64_t Cost) {

Callers 1

enterFunctionMethod · 0.80

Calls 3

unlikelyFunction · 0.85
errorFunction · 0.50
loadMethod · 0.45

Tested by

no test coverage detected