MCPcopy Create free account
hub / github.com/apache/trafficserver / try_lock_shared

Method try_lock_shared

include/tsutil/Bravo.h:279–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277 }
278
279 bool
280 try_lock_shared(Token &token)
281 {
282 debug_assert(SLOT_SIZE >= DenseThreadId::num_possible_values());
283
284 // Fast path
285 if (_mutex.read_bias.load(std::memory_order_acquire)) {
286 size_t index = DenseThreadId::self() % SLOT_SIZE;
287 Slot &slot = _mutex.readers[index];
288 bool expect = false;
289
290 if (slot.mu.compare_exchange_weak(expect, true, std::memory_order_release, std::memory_order_relaxed)) {
291 // recheck
292 if (_mutex.read_bias.load(std::memory_order_acquire)) {
293 token = index + 1;
294 return true;
295 } else {
296 slot.mu.store(false, std::memory_order_relaxed);
297 }
298 }
299 }
300
301 // Slow path
302 bool r = _mutex.underlying.try_lock_shared();
303 if (r) {
304 // Set RBias if the BRAVO policy allows that
305 if (_mutex.read_bias.load(std::memory_order_acquire) == false && _now() >= _mutex.inhibit_until) {
306 _mutex.read_bias.store(true, std::memory_order_release);
307 }
308
309 return true;
310 }
311
312 return false;
313 }
314
315 void
316 unlock_shared(const Token token)

Callers 2

test_Bravo.ccFile · 0.45
try_lockMethod · 0.45

Calls 2

loadMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected