MCPcopy Create free account
hub / github.com/bytedance/bolt / setExclusiveToShared

Method setExclusiveToShared

bolt/common/caching/AsyncDataCache.cpp:54–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54void AsyncDataCacheEntry::setExclusiveToShared(bool cacheable) {
55 BOLT_CHECK(isExclusive());
56 numPins_ = 1;
57 std::unique_ptr<folly::SharedPromise<bool>> promise;
58 {
59 std::lock_guard<std::mutex> l(shard_->mutex());
60 // Enter the shard's mutex to make sure a promise is not being added during
61 // the move.
62 promise = std::move(promise_);
63 }
64 if (promise != nullptr) {
65 promise->setValue(true);
66 }
67
68 // The entry may now have other readers, It is safe to do read-only ops like
69 // integrity and notifying SSD cache of another candidate.
70 const auto& hook = shard_->cache()->verifyHook();
71 if (hook != nullptr) {
72 hook(*this);
73 }
74
75 if (cacheable && (ssdFile_ == nullptr) &&
76 (shard_->cache()->ssdCache() != nullptr)) {
77 auto* ssdCache = shard_->cache()->ssdCache();
78 assert(ssdCache); // for lint only.
79 if (ssdCache->groupStats().shouldSaveToSsd(groupId_, trackingId_)) {
80 ssdSaveable_ = true;
81 shard_->cache()->possibleSsdSave(size_);
82 }
83 }
84}
85
86void AsyncDataCacheEntry::release() {
87 BOLT_CHECK_NE(0, numPins_);

Callers 6

loadSyncMethod · 0.80
loadFromSsdMethod · 0.80
loadOrFutureMethod · 0.80
loadOneMethod · 0.80
TEST_FFunction · 0.80
DEBUG_ONLY_TEST_FFunction · 0.80

Calls 5

ssdCacheMethod · 0.80
shouldSaveToSsdMethod · 0.80
possibleSsdSaveMethod · 0.80
setValueMethod · 0.45
cacheMethod · 0.45

Tested by 3

loadOneMethod · 0.64
TEST_FFunction · 0.64
DEBUG_ONLY_TEST_FFunction · 0.64