42 #include "qplatformdefs.h"
50 #include "private/qfreelist_p.h"
51 #include "private/qlocking_p.h"
71 using ms = std::chrono::milliseconds;
163 auto d = d_ptr.loadAcquire();
165 qWarning(
"QReadWriteLock: destroying locked QReadWriteLock");
245 "Overflow in lock counter");
246 if (!d_ptr.testAndSetAcquire(
d,
val,
d))
257 val->writerCount = 1;
258 if (!d_ptr.testAndSetOrdered(
d,
val,
d)) {
259 val->writerCount = 0;
269 return d->recursiveLockForRead(
timeout);
272 if (
d != d_ptr.loadRelaxed()) {
279 d = d_ptr.loadAcquire();
362 val->writerCount = 1;
365 if (!d_ptr.testAndSetOrdered(
d,
val,
d)) {
366 val->writerCount =
val->readerCount = 0;
376 return d->recursiveLockForWrite(
timeout);
379 if (
d != d_ptr.loadRelaxed()) {
383 d = d_ptr.loadAcquire();
402 Q_ASSERT_X(
d,
"QReadWriteLock::unlock()",
"Cannot unlock an unlocked lock");
406 if (!d_ptr.testAndSetOrdered(
d,
nullptr,
d))
415 if (!d_ptr.testAndSetOrdered(
d,
val,
d))
423 d->recursiveUnlock();
428 if (
d->writerCount) {
435 if (
d->readerCount > 0)
439 if (
d->waitingReaders ||
d->waitingWriters) {
443 d_ptr.storeRelease(
nullptr);
451 QReadWriteLock::StateForWaitCondition QReadWriteLock::stateForWaitCondition()
const
462 if (
d->writerCount > 1)
463 return RecursivelyLocked;
464 else if (
d->writerCount == 1)
465 return LockedForWrite;
466 return LockedForRead;
482 auto elapsed =
t.elapsed();
510 auto elapsed =
t.elapsed();
558 ++
it->recursionLevel;
602 qWarning(
"QReadWriteLock::unlock: unlocking from a thread that did not lock");
605 if (--
it->recursionLevel <= 0) {
620 enum { BlockCount = 4, MaxIndex=0xffff };
623 const int FreeListConstants::Sizes[FreeListConstants::BlockCount] = {
627 FreeListConstants::MaxIndex - (16 + 128 + 1024)
636 int i = freelist->next();
640 Q_ASSERT(!
d->waitingReaders && !
d->waitingWriters && !
d->readerCount && !
d->writerCount);
648 freelist->release(
id);
small capitals from c petite p scientific i
[1]
The QElapsedTimer class provides a fast way to calculate elapsed times.
void lockForRead() noexcept
bool tryLockForWrite() noexcept
QReadWriteLock(RecursionMode=NonRecursive) noexcept
bool tryLockForRead() noexcept
void lockForWrite() noexcept
QtPrivate::condition_variable readerCond
bool lockForWrite(std::unique_lock< QtPrivate::mutex > &lock, int timeout)
bool recursiveLockForRead(int timeout)
QtPrivate::condition_variable writerCond
bool recursiveLockForWrite(int timeout)
static QReadWriteLockPrivate * allocate()
bool lockForRead(std::unique_lock< QtPrivate::mutex > &lock, int timeout)
QVarLengthArray< Reader, 16 > currentReaders
static Qt::HANDLE currentThreadId() noexcept Q_DECL_PURE_FUNCTION
cv_status wait_for(std::unique_lock< QtPrivate::mutex > &lock, const std::chrono::duration< Rep, Period > &d)
void wait(std::unique_lock< QtPrivate::mutex > &lock)
std::chrono::milliseconds ms
Lock qt_scoped_lock(Mutex &mutex)
Lock qt_unique_lock(Mutex &mutex)
bool isUncontendedLocked(const QReadWriteLockPrivate *d)
const auto dummyLockedForRead
const auto dummyLockedForWrite
QImageReader reader("image.png")
[1]
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLuint64 GLenum void * handle
GLbitfield GLuint64 timeout
[4]
#define Q_ASSERT_X(cond, x, msg)