MCPcopy Create free account
hub / github.com/apache/thrift / incrementCounter

Method incrementCounter

contrib/fb303/cpp/FacebookBase.cpp:49–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49int64_t FacebookBase::incrementCounter(const std::string& key, int64_t amount) {
50 counters_.lock();
51
52 // if we didn't find the key, we need to write lock the whole map to create it
53 ReadWriteCounterMap::iterator it = counters_.find(key);
54 if (it == counters_.end()) {
55
56 // we need to check again to make sure someone didn't create this key
57 // already while we released the lock
58 it = counters_.find(key);
59 if(it == counters_.end()){
60 counters_[key].value = amount;
61 counters_.unlock();
62 return amount;
63 }
64 }
65
66 it->second.lock();
67 int64_t count = it->second.value + amount;
68 it->second.value = count;
69 it->second.unlock();
70 counters_.unlock();
71 return count;
72}
73
74int64_t FacebookBase::setCounter(const std::string& key, int64_t value) {
75 counters_.lock();

Callers 1

finishServiceMethod · 0.45

Calls 4

findMethod · 0.80
lockMethod · 0.45
endMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected