MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / acquireWrite

Method acquireWrite

src/readwritelock.h:37–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 }
36
37 void acquireWrite(bool exclusive = true) {
38 std::unique_lock<fastlock> rm(m_readLock, std::defer_lock);
39 if (m_multi) {
40 rm.lock();
41 m_writeWaiting = true;
42 while (m_readCount > 0)
43 m_cv.wait(rm);
44 if (exclusive) {
45 /* Another thread might have the write lock while we have the internal lock
46 but won't be able to release it until they can acquire the internal lock
47 so release the internal lock and try again instead of waiting to avoid deadlock */
48 while(!m_writeLock.try_lock())
49 m_cv.wait(rm);
50 }
51 }
52 m_writeCount++;
53 m_writeWaiting = false;
54 }
55
56 void upgradeWrite(bool exclusive = true) {
57 releaseRead();

Callers 1

moduleAcquireGILFunction · 0.80

Calls 3

lockMethod · 0.45
waitMethod · 0.45
try_lockMethod · 0.45

Tested by

no test coverage detected