summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2014-10-28 18:20:22 +0100
committerMilian Wolff <milian.wolff@kdab.com>2014-10-29 14:37:55 +0100
commit68df6de8b2c1560e96f00ab3eb18e0c575688394 (patch)
tree4206abe037ae7e39fafb68d5fb5b4f0ac190cbab /tests
parented7e4de6b3a164cdfbf53338a298877ac12ac8ba (diff)
Optimize: Use a plain non-recursive QMutex in the QResourceManager.
The overhead of a read/write lock should not be required for such small critical sections. It will also allow us to cleanup the code a bit more. Already, the code changes lead to a small improvement before: RESULT : tst_QResourcesManager::benchmarkAllocateSmallResources(): 46,552,767 instructions per iteration (total: 46,552,767, iterations: 1) RESULT : tst_QResourcesManager::benchmarkAllocateBigResources(): 48,338,703 instructions per iteration (total: 48,338,703, iterations: 1) after: RESULT : tst_QResourcesManager::benchmarkAllocateSmallResources(): 44,848,672 instructions per iteration (total: 44,848,672, iterations: 1) RESULT : tst_QResourcesManager::benchmarkAllocateBigResources(): 46,634,161 instructions per iteration (total: 46,634,161, iterations: 1) Change-Id: I8ef0aa52be3caf8b4c8691579677f693a054565c Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp10
-rw-r--r--tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/tst_preallocatedarraypolicy.cpp9
-rw-r--r--tests/auto/core/listresourcesmanager/tst_listresourcesmanager.cpp10
3 files changed, 12 insertions, 17 deletions
diff --git a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp b/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp
index 1b41055b4..90b48ba10 100644
--- a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp
+++ b/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp
@@ -71,7 +71,7 @@ public:
tst_ArrayResource() : m_value(0)
{}
- int m_value;
+ QAtomicInt m_value;
};
typedef Qt3D::QHandle<tst_ArrayResource> tHandle;
@@ -298,8 +298,7 @@ protected:
tst_ArrayResource *r = m_manager->getOrCreateResource(i);
i++;
QVERIFY(r != Q_NULLPTR);
- Manager::WriteLocker lock(m_manager);
- r->m_value++;
+ r->m_value.fetchAndAddOrdered(+1);
}
qDebug() << QThread::currentThread() << "Done";
}
@@ -370,9 +369,8 @@ protected:
while (i < max) {
tst_ArrayResource *r = m_manager->getOrCreateResource(i);
QVERIFY(r != Q_NULLPTR);
- Manager::WriteLocker lock(m_manager);
- r->m_value++;
- if (r->m_value > m_releaseAbove)
+ int oldValue = r->m_value.fetchAndAddOrdered(+1);
+ if (oldValue == m_releaseAbove)
m_manager->releaseResource(i);
i++;
}
diff --git a/tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/tst_preallocatedarraypolicy.cpp b/tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/tst_preallocatedarraypolicy.cpp
index b9c18d95e..ffdccf847 100644
--- a/tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/tst_preallocatedarraypolicy.cpp
+++ b/tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/tst_preallocatedarraypolicy.cpp
@@ -71,7 +71,7 @@ public:
tst_ArrayResource() : m_value(0)
{}
- int m_value;
+ QAtomicInt m_value;
};
typedef Qt3D::QHandle<tst_ArrayResource> tHandle;
@@ -298,7 +298,7 @@ protected:
tst_ArrayResource *r = m_manager->getOrCreateResource(i);
i++;
QVERIFY(r != Q_NULLPTR);
- Manager::WriteLocker lock(m_manager);
+ Manager::Locker lock(m_manager);
r->m_value++;
}
qDebug() << QThread::currentThread() << "Done";
@@ -370,9 +370,8 @@ protected:
while (i < max) {
tst_ArrayResource *r = m_manager->getOrCreateResource(i);
QVERIFY(r != Q_NULLPTR);
- Manager::WriteLocker lock(m_manager);
- r->m_value++;
- if (r->m_value > m_releaseAbove)
+ int oldValue = r->m_value.fetchAndAddOrdered(+1);
+ if (oldValue == m_releaseAbove)
m_manager->releaseResource(i);
i++;
}
diff --git a/tests/auto/core/listresourcesmanager/tst_listresourcesmanager.cpp b/tests/auto/core/listresourcesmanager/tst_listresourcesmanager.cpp
index b5bee9b88..abf695093 100644
--- a/tests/auto/core/listresourcesmanager/tst_listresourcesmanager.cpp
+++ b/tests/auto/core/listresourcesmanager/tst_listresourcesmanager.cpp
@@ -71,7 +71,7 @@ public:
tst_ListResource() : m_value(0)
{}
- int m_value;
+ QAtomicInt m_value;
};
typedef Qt3D::QHandle<tst_ListResource> tHandle;
@@ -298,8 +298,7 @@ protected:
tst_ListResource *r = m_manager->getOrCreateResource(i);
i++;
QVERIFY(r != Q_NULLPTR);
- Manager::WriteLocker lock(m_manager);
- r->m_value++;
+ r->m_value.fetchAndAddOrdered(+1);
}
qDebug() << QThread::currentThread() << "Done";
}
@@ -371,9 +370,8 @@ protected:
while (i < max) {
tst_ListResource *r = m_manager->getOrCreateResource(i);
QVERIFY(r != Q_NULLPTR);
- Manager::WriteLocker lock(m_manager);
- r->m_value++;
- if (r->m_value > m_releaseAbove)
+ int oldValue = r->m_value.fetchAndAddOrdered(+1);
+ if (oldValue == m_releaseAbove)
m_manager->releaseResource(i);
i++;
}