Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qreadwritelock_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QREADWRITELOCK_P_H
6#define QREADWRITELOCK_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the implementation. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/private/qlocking_p.h>
20#include <QtCore/private/qwaitcondition_p.h>
21#include <QtCore/qreadwritelock.h>
22#include <QtCore/qvarlengtharray.h>
23
25
27
41
43{
44public:
45 explicit QReadWriteLockPrivate(bool isRecursive = false)
46 : recursive(isRecursive) {}
47
48 alignas(QtPrivate::IdealMutexAlignment) std::condition_variable writerCond;
49 std::condition_variable readerCond;
50
52 int readerCount = 0;
53 int writerCount = 0;
56 const bool recursive;
57
58 //Called with the mutex locked
59 bool lockForWrite(std::unique_lock<std::mutex> &lock, QDeadlineTimer timeout);
60 bool lockForRead(std::unique_lock<std::mutex> &lock, QDeadlineTimer timeout);
61 void unlock();
62
63 //memory management
64 int id = 0;
65 void release();
67
68 // Recursive mutex handling
70
75
76 QVarLengthArray<Reader, 16> currentReaders;
77
78 // called with the mutex unlocked
81 void recursiveUnlock();
82
85};
87
91{
92 using namespace QReadWriteLockStates;
93 QReadWriteLockPrivate *d = q->d_ptr.loadAcquire();
94 switch (quintptr(d) & StateMask) {
95 case StateLockedForRead: return LockedForRead;
96 case StateLockedForWrite: return LockedForWrite;
97 }
98
99 if (!d)
100 return Unlocked;
101 const auto lock = qt_scoped_lock(d->mutex);
102 if (d->writerCount > 1)
103 return RecursivelyLocked;
104 else if (d->writerCount == 1)
105 return LockedForWrite;
106 return LockedForRead;
107
108}
109
111
112#endif // QREADWRITELOCK_P_H
\inmodule QtCore
std::condition_variable readerCond
bool lockForRead(std::unique_lock< std::mutex > &lock, QDeadlineTimer timeout)
bool lockForWrite(std::unique_lock< std::mutex > &lock, QDeadlineTimer timeout)
bool recursiveLockForRead(QDeadlineTimer timeout)
bool recursiveLockForWrite(QDeadlineTimer timeout)
static QReadWriteLockPrivate * allocate()
static QReadWriteLockStates::StateForWaitCondition stateForWaitCondition(const QReadWriteLock *lock)
QReadWriteLockPrivate(bool isRecursive=false)
std::condition_variable writerCond
QVarLengthArray< Reader, 16 > currentReaders
\inmodule QtCore
Combined button and popup list for selecting options.
static constexpr quintptr IdealMutexAlignment
void * HANDLE
GLbitfield GLuint64 timeout
[4]
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define QT_REQUIRE_CONFIG(feature)
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:157
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
size_t quintptr
Definition qtypes.h:167
QReadWriteLock lock
[0]