kdevplatform/language/duchain
Go to the documentation of this file.
26 #include <QThreadStorage>
27 #include <QElapsedTimer>
36 class DUChainLockPrivate
41 , m_writerRecursion(0)
42 , m_totalReaderRecursion(0)
45 int ownReaderRecursion()
const
47 return m_readerRecursion.localData();
50 void changeOwnReaderRecursion(
int difference)
52 m_readerRecursion.localData() += difference;
53 Q_ASSERT(m_readerRecursion.localData() >= 0);
54 m_totalReaderRecursion.fetchAndAddOrdered(difference);
70 : d_ptr(new DUChainLockPrivate)
81 d->changeOwnReaderRecursion(1);
83 QThread* w = d->m_writer.loadAcquire();
94 while (d->m_writer.loadAcquire()) {
95 if (!timeout || t.
elapsed() < timeout) {
99 d->changeOwnReaderRecursion(-1);
112 d->changeOwnReaderRecursion(-1);
119 return (
bool )d->ownReaderRecursion();
128 Q_ASSERT(d->ownReaderRecursion() == 0);
130 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
136 d->m_writerRecursion.fetchAndAddRelaxed(1);
147 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
148 if (d->m_totalReaderRecursion.loadRelaxed() == 0 &&
150 if (d->m_totalReaderRecursion.load() == 0 &&
152 d->m_writerRecursion.testAndSetOrdered(0, 1)) {
155 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
156 if (d->m_totalReaderRecursion.loadRelaxed() == 0) {
158 if (d->m_totalReaderRecursion.load() == 0) {
164 d->m_writer =
nullptr;
165 d->m_writerRecursion = 0;
169 if (!timeout || t.
elapsed() < timeout) {
189 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
190 if (d->m_writerRecursion.loadRelaxed() == 1) {
192 if (d->m_writerRecursion.load() == 1) {
194 d->m_writer =
nullptr;
195 d->m_writerRecursion = 0;
197 d->m_writerRecursion.fetchAndAddOrdered(-1);
205 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
213 : m_lock(duChainLock ? duChainLock :
DUChain::lock())
239 Q_ASSERT(m_timeout || l);
250 if (m_locked && m_lock) {
257 : m_lock(duChainLock ? duChainLock :
DUChain::lock())
278 Q_ASSERT(m_timeout || l);
294 if (m_locked && m_lock) {
bool lockForWrite(unsigned int timeout=0)
Acquires a write lock.
void unlock()
Unlock the read lock.
bool lock()
Acquire the read lock (again). Uses the same timeout given to the constructor.
void releaseReadLock()
Releases a previously acquired read lock.
bool lockForRead(unsigned int timeout=0)
Acquires a read lock.
DUChainWriteLocker(DUChainLock *duChainLock=nullptr, unsigned int timeout=0)
Constructor.
DUChainLock()
Constructor.
bool locked() const
Returns true if a lock was requested and the lock succeeded, else false.
~DUChainReadLocker()
Destructor.
Customized read/write locker for the definition-use chain.
bool currentThreadHasReadLock()
Determines if the current thread has a read lock.
bool currentThreadHasWriteLock() const
Determines if the current thread has a write lock.
bool locked() const
Returns true if a lock was requested and the lock succeeded, else false.
QThread * currentThread()
void usleep(unsigned long usecs)
~DUChainLock()
Destructor.
bool lock()
Acquire the write lock (again). Uses the same timeout given to the constructor.
~DUChainWriteLocker()
Destructor.
DUChainReadLocker(DUChainLock *duChainLock=nullptr, unsigned int timeout=0)
Constructor.
void unlock()
Unlock the write lock.
Holds references to all top level source file contexts.
void releaseWriteLock()
Releases a previously acquired write lock.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 16 2021 23:35:05 by
doxygen 1.8.16 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.