MCPcopy Create free account
hub / github.com/facebook/CacheLib / getShort

Method getShort

cachelib/cachebench/consistency/ShortThreadId.cpp:27–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace cachelib {
26namespace cachebench {
27ShortThreadId ShortThreadIdMap::getShort(std::thread::id tid) {
28 {
29 std::shared_lock<folly::SharedMutex> lock{mutex_};
30 auto iter = tids_.find(tid);
31 if (iter != tids_.end()) {
32 return iter->second;
33 }
34 }
35
36 // Now we have to insert a new TID. Take writer lock. Remember to check
37 // again if present!
38 std::lock_guard<folly::SharedMutex> lock{mutex_};
39 auto iter = tids_.find(tid);
40 if (iter != tids_.end()) {
41 return iter->second;
42 }
43 auto size = tids_.size();
44 if (size > std::numeric_limits<ShortThreadId>::max()) {
45 throw std::out_of_range("too many threads");
46 }
47 // "first" is an iterator pointing to the inserted key/value pair
48 return tids_.emplace(tid, static_cast<ShortThreadId>(size)).first->second;
49}
50} // namespace cachebench
51} // namespace cachelib
52} // namespace facebook

Callers 2

eventInfoMethod · 0.80
TESTFunction · 0.80

Calls 3

findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.64