MCPcopy Create free account
hub / github.com/KDE/kdevelop / lockForRead

Method lockForRead

kdevplatform/language/duchain/duchainlock.cpp:64–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62DUChainLock::~DUChainLock() = default;
63
64bool DUChainLock::lockForRead(unsigned int timeout)
65{
66 Q_D(DUChainLock);
67
68 ///Step 1: Increase the own reader-recursion. This will make sure no further write-locks will succeed
69 d->changeOwnReaderRecursion(1);
70
71 QThread* w = d->m_writer.loadAcquire();
72 if (w == nullptr || w == QThread::currentThread()) {
73 //Successful lock: Either there is no writer, or we hold the write-lock by ourselves
74 } else {
75 ///Step 2: Start spinning until there is no writer any more
76
77 QElapsedTimer t;
78 if (timeout) {
79 t.start();
80 }
81
82 while (d->m_writer.loadAcquire()) {
83 if (!timeout || t.elapsed() < timeout) {
84 QThread::usleep(uSleepTime);
85 } else {
86 //Fail!
87 d->changeOwnReaderRecursion(-1);
88 return false;
89 }
90 }
91 }
92
93 return true;
94}
95
96void DUChainLock::releaseReadLock()
97{

Callers 1

lockMethod · 0.45

Calls 3

elapsedMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected