summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp')
-rw-r--r--tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp95
1 files changed, 68 insertions, 27 deletions
diff --git a/tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp b/tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp
index be12877df1..e63ac6573f 100644
--- a/tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp
+++ b/tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QtCore>
#include <QTest>
@@ -44,6 +19,49 @@ struct LockerWrapper : T
}
};
+struct QRecursiveReadWriteLock : QReadWriteLock
+{
+ QRecursiveReadWriteLock() : QReadWriteLock(Recursive) {}
+};
+
+template <typename T, size_t N>
+ // requires N = 2^M for some Integral M >= 0
+struct Recursive
+{
+ Recursive<T, N/2> r1, r2;
+
+ template <typename...Args>
+ Q_ALWAYS_INLINE
+ explicit Recursive(Args &&...args)
+ : r1(args...),
+ r2(args...)
+ {}
+};
+
+template <typename T>
+struct Recursive<T, 1>
+{
+ T t;
+ template <typename...Args>
+ Q_ALWAYS_INLINE
+ explicit Recursive(Args &&...args)
+ : t(args...) {}
+};
+
+template <typename T>
+struct Recursive<T, 0>
+{
+ template <typename...Args>
+ Q_ALWAYS_INLINE
+ explicit Recursive(Args &&...) {}
+};
+
+template <size_t N>
+using QRecursiveReadLocker = Recursive<QReadLocker, N>;
+
+template <size_t N>
+using QRecursiveWriteLocker = Recursive<QWriteLocker, N>;
+
int threadCount;
class tst_QReadWriteLock : public QObject
@@ -105,6 +123,15 @@ void tst_QReadWriteLock::uncontended_data()
<< FunctionPtrHolder(testUncontended<QReadWriteLock, QReadLocker>);
QTest::newRow("QReadWriteLock, write")
<< FunctionPtrHolder(testUncontended<QReadWriteLock, QWriteLocker>);
+#define ROW(n) \
+ QTest::addRow("QReadWriteLock, %s, recursive: %d", "read", n) \
+ << FunctionPtrHolder(testUncontended<QRecursiveReadWriteLock, QRecursiveReadLocker<n>>); \
+ QTest::addRow("QReadWriteLock, %s, recursive: %d", "write", n) \
+ << FunctionPtrHolder(testUncontended<QRecursiveReadWriteLock, QRecursiveWriteLocker<n>>)
+ ROW(1);
+ ROW(2);
+ ROW(32);
+#undef ROW
QTest::newRow("std::mutex") << FunctionPtrHolder(
testUncontended<std::mutex, LockerWrapper<std::unique_lock<std::mutex>>>);
#ifdef __cpp_lib_shared_mutex
@@ -172,6 +199,13 @@ void tst_QReadWriteLock::readOnly_data()
QTest::newRow("nothing") << FunctionPtrHolder(testReadOnly<int, FakeLock>);
QTest::newRow("QMutex") << FunctionPtrHolder(testReadOnly<QMutex, QMutexLocker<QMutex>>);
QTest::newRow("QReadWriteLock") << FunctionPtrHolder(testReadOnly<QReadWriteLock, QReadLocker>);
+#define ROW(n) \
+ QTest::addRow("QReadWriteLock, recursive: %d", n) \
+ << FunctionPtrHolder(testReadOnly<QRecursiveReadWriteLock, QRecursiveReadLocker<n>>)
+ ROW(1);
+ ROW(2);
+ ROW(32);
+#undef ROW
QTest::newRow("std::mutex") << FunctionPtrHolder(
testReadOnly<std::mutex, LockerWrapper<std::unique_lock<std::mutex>>>);
#ifdef __cpp_lib_shared_mutex
@@ -233,6 +267,13 @@ void tst_QReadWriteLock::writeOnly_data()
// QTest::newRow("nothing") << FunctionPtrHolder(testWriteOnly<int, FakeLock>);
QTest::newRow("QMutex") << FunctionPtrHolder(testWriteOnly<QMutex, QMutexLocker<QMutex>>);
QTest::newRow("QReadWriteLock") << FunctionPtrHolder(testWriteOnly<QReadWriteLock, QWriteLocker>);
+#define ROW(n) \
+ QTest::addRow("QReadWriteLock, recursive: %d", n) \
+ << FunctionPtrHolder(testWriteOnly<QRecursiveReadWriteLock, QRecursiveWriteLocker<n>>)
+ ROW(1);
+ ROW(2);
+ ROW(32);
+#undef ROW
QTest::newRow("std::mutex") << FunctionPtrHolder(
testWriteOnly<std::mutex, LockerWrapper<std::unique_lock<std::mutex>>>);
#ifdef __cpp_lib_shared_mutex