QReadWriteLock: inline the constructor and destructor
Change-Id: Ieab617d69f3b4b54ab30fffd175b2500dd860431 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
6ac0406464
commit
4f00e6c8b9
@ -101,6 +101,7 @@ static bool contendedTryLockForWrite(QAtomicPointer<QReadWriteLockPrivate> &d_pt
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
\fn QReadWriteLock::QReadWriteLock(RecursionMode recursionMode)
|
||||||
\since 4.4
|
\since 4.4
|
||||||
|
|
||||||
Constructs a QReadWriteLock object in the given \a recursionMode.
|
Constructs a QReadWriteLock object in the given \a recursionMode.
|
||||||
@ -109,21 +110,22 @@ static bool contendedTryLockForWrite(QAtomicPointer<QReadWriteLockPrivate> &d_pt
|
|||||||
|
|
||||||
\sa lockForRead(), lockForWrite(), RecursionMode
|
\sa lockForRead(), lockForWrite(), RecursionMode
|
||||||
*/
|
*/
|
||||||
QReadWriteLock::QReadWriteLock(RecursionMode recursionMode)
|
QReadWriteLockPrivate *QReadWriteLock::initRecursive()
|
||||||
: d_ptr(recursionMode == Recursive ? new QReadWriteLockPrivate(true) : nullptr)
|
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(!(quintptr(d_ptr.loadRelaxed()) & StateMask), "QReadWriteLock::QReadWriteLock", "bad d_ptr alignment");
|
auto d = new QReadWriteLockPrivate(true);
|
||||||
|
Q_ASSERT_X(!(quintptr(d) & StateMask), "QReadWriteLock::QReadWriteLock", "bad d_ptr alignment");
|
||||||
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
\fn QReadWriteLock::~QReadWriteLock()
|
||||||
Destroys the QReadWriteLock object.
|
Destroys the QReadWriteLock object.
|
||||||
|
|
||||||
\warning Destroying a read-write lock that is in use may result
|
\warning Destroying a read-write lock that is in use may result
|
||||||
in undefined behavior.
|
in undefined behavior.
|
||||||
*/
|
*/
|
||||||
QReadWriteLock::~QReadWriteLock()
|
void QReadWriteLock::destroyRecursive(QReadWriteLockPrivate *d)
|
||||||
{
|
{
|
||||||
auto d = d_ptr.loadAcquire();
|
|
||||||
if (isUncontendedLocked(d)) {
|
if (isUncontendedLocked(d)) {
|
||||||
qWarning("QReadWriteLock: destroying locked QReadWriteLock");
|
qWarning("QReadWriteLock: destroying locked QReadWriteLock");
|
||||||
return;
|
return;
|
||||||
|
@ -18,7 +18,9 @@ class Q_CORE_EXPORT QReadWriteLock
|
|||||||
public:
|
public:
|
||||||
enum RecursionMode { NonRecursive, Recursive };
|
enum RecursionMode { NonRecursive, Recursive };
|
||||||
|
|
||||||
|
QT_CORE_INLINE_SINCE(6, 6)
|
||||||
explicit QReadWriteLock(RecursionMode recursionMode = NonRecursive);
|
explicit QReadWriteLock(RecursionMode recursionMode = NonRecursive);
|
||||||
|
QT_CORE_INLINE_SINCE(6, 6)
|
||||||
~QReadWriteLock();
|
~QReadWriteLock();
|
||||||
|
|
||||||
QT_CORE_INLINE_SINCE(6, 6)
|
QT_CORE_INLINE_SINCE(6, 6)
|
||||||
@ -54,9 +56,22 @@ private:
|
|||||||
Q_DISABLE_COPY(QReadWriteLock)
|
Q_DISABLE_COPY(QReadWriteLock)
|
||||||
QAtomicPointer<QReadWriteLockPrivate> d_ptr;
|
QAtomicPointer<QReadWriteLockPrivate> d_ptr;
|
||||||
friend class QReadWriteLockPrivate;
|
friend class QReadWriteLockPrivate;
|
||||||
|
static QReadWriteLockPrivate *initRecursive();
|
||||||
|
static void destroyRecursive(QReadWriteLockPrivate *);
|
||||||
};
|
};
|
||||||
|
|
||||||
#if QT_CORE_INLINE_IMPL_SINCE(6, 6)
|
#if QT_CORE_INLINE_IMPL_SINCE(6, 6)
|
||||||
|
QReadWriteLock::QReadWriteLock(RecursionMode recursionMode)
|
||||||
|
: d_ptr(recursionMode == Recursive ? initRecursive() : nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QReadWriteLock::~QReadWriteLock()
|
||||||
|
{
|
||||||
|
if (auto d = d_ptr.loadAcquire())
|
||||||
|
destroyRecursive(d);
|
||||||
|
}
|
||||||
|
|
||||||
void QReadWriteLock::lockForRead()
|
void QReadWriteLock::lockForRead()
|
||||||
{
|
{
|
||||||
tryLockForRead(QDeadlineTimer(QDeadlineTimer::Forever));
|
tryLockForRead(QDeadlineTimer(QDeadlineTimer::Forever));
|
||||||
|
Loading…
Reference in New Issue
Block a user