summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-04-17 16:49:58 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-05-11 12:31:56 -0700
commitfcae43237b7501d9da1dc1b838bf4cdb28d3fd91 (patch)
tree1364665e94d292ca945a275d26dc9b67d0feaaca /src/corelib
parent34914099a1044beba7fdd1b71b079c4130ca0cd4 (diff)
QReadWriteLock: inline the lockForXxx functions
We can now do that because tryLockForXxxx(-1) is fast for the uncontended case too. Change-Id: I3d728c4197df49169066fffd1756ddd06caf7b52 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/compat/removed_api.cpp4
-rw-r--r--src/corelib/thread/qreadwritelock.cpp10
-rw-r--r--src/corelib/thread/qreadwritelock.h14
3 files changed, 20 insertions, 8 deletions
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp
index b7c5ae8453..d810da59e8 100644
--- a/src/corelib/compat/removed_api.cpp
+++ b/src/corelib/compat/removed_api.cpp
@@ -601,6 +601,10 @@ QStringView QXmlStreamAttributes::value(QLatin1StringView qualifiedName) const
return value(QAnyStringView(qualifiedName));
}
+// inlined API
+#if QT_CONFIG(thread)
+#include "qreadwritelock.h"
+#endif
// #include "qotherheader.h"
// // implement removed functions from qotherheader.h
diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp
index 7e29aa3905..36f051408e 100644
--- a/src/corelib/thread/qreadwritelock.cpp
+++ b/src/corelib/thread/qreadwritelock.cpp
@@ -132,6 +132,7 @@ QReadWriteLock::~QReadWriteLock()
}
/*!
+ \fn QReadWriteLock::lockForRead()
Locks the lock for reading. This function will block the current
thread if another thread has locked for writing.
@@ -140,10 +141,6 @@ QReadWriteLock::~QReadWriteLock()
\sa unlock(), lockForWrite(), tryLockForRead()
*/
-void QReadWriteLock::lockForRead()
-{
- tryLockForRead(-1);
-}
/*!
@@ -229,6 +226,7 @@ Q_NEVER_INLINE static bool contendedTryLockForRead(QAtomicPointer<QReadWriteLock
}
/*!
+ \fn QReadWriteLock::lockForWrite()
Locks the lock for writing. This function will block the current
thread if another thread (including the current) has locked for
reading or writing (unless the lock has been created using the
@@ -239,10 +237,6 @@ Q_NEVER_INLINE static bool contendedTryLockForRead(QAtomicPointer<QReadWriteLock
\sa unlock(), lockForRead(), tryLockForWrite()
*/
-void QReadWriteLock::lockForWrite()
-{
- tryLockForWrite(-1);
-}
/*!
Attempts to lock for writing. This function returns \c true if the
diff --git a/src/corelib/thread/qreadwritelock.h b/src/corelib/thread/qreadwritelock.h
index 1a94386386..4db44784e3 100644
--- a/src/corelib/thread/qreadwritelock.h
+++ b/src/corelib/thread/qreadwritelock.h
@@ -21,12 +21,14 @@ public:
explicit QReadWriteLock(RecursionMode recursionMode = NonRecursive);
~QReadWriteLock();
+ QT_CORE_INLINE_SINCE(6, 6)
void lockForRead();
#if QT_CORE_REMOVED_SINCE(6, 6)
bool tryLockForRead();
#endif
bool tryLockForRead(int timeout = 0);
+ QT_CORE_INLINE_SINCE(6, 6)
void lockForWrite();
#if QT_CORE_REMOVED_SINCE(6, 6)
bool tryLockForWrite();
@@ -41,6 +43,18 @@ private:
friend class QReadWriteLockPrivate;
};
+#if QT_CORE_INLINE_IMPL_SINCE(6, 6)
+void QReadWriteLock::lockForRead()
+{
+ tryLockForRead(-1);
+}
+
+void QReadWriteLock::lockForWrite()
+{
+ tryLockForWrite(-1);
+}
+#endif // inline since 6.6
+
#if defined(Q_CC_MSVC)
#pragma warning( push )
#pragma warning( disable : 4312 ) // ignoring the warning from /Wp64