summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-09-05 14:21:09 +0200
committerSean Harmer <sean.harmer@kdab.com>2017-09-11 08:57:48 +0000
commit837a56fa10b26f129cb0a70caaff9f84e00a3acb (patch)
treec91de86edfa3d61c3544f00d3fb5924533d3f5b8
parent64d018ea11e00174cedabda9230a93054b40d79b (diff)
Get rid of the HandleManager class
Instead, direclty use the Allocator to acquire and release handles without an additional indirection. This removes around 30% of the overhead in run(). Change-Id: Ic4a9343dd52a900eb1c7eb6b4135bc7670076df1 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/core/resources/qhandle_p.h27
-rw-r--r--src/core/resources/qhandlemanager_p.h263
-rw-r--r--src/core/resources/qresourcemanager_p.h144
-rw-r--r--src/core/resources/resources.pri1
-rw-r--r--src/render/backend/managers_p.h5
-rw-r--r--tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp31
-rw-r--r--tests/auto/core/core.pro1
-rw-r--r--tests/auto/core/handlemanager/handlemanager.pro7
-rw-r--r--tests/auto/core/handlemanager/tst_handlemanager.cpp306
-rw-r--r--tests/benchmarks/core/qresourcesmanager/arraypolicy/tst_bench_arraypolicy.cpp2
-rw-r--r--tests/benchmarks/core/qresourcesmanager/qresourcesmanager/tst_bench_qresourcesmanager.cpp2
11 files changed, 88 insertions, 701 deletions
diff --git a/src/core/resources/qhandle_p.h b/src/core/resources/qhandle_p.h
index 94dc7ca45..c4b53ec21 100644
--- a/src/core/resources/qhandle_p.h
+++ b/src/core/resources/qhandle_p.h
@@ -53,6 +53,7 @@
#include <Qt3DCore/qt3dcore_global.h>
#include <QtCore/QDebug>
+#include <limits.h>
class tst_Handle; // needed for friend class declaration below
@@ -60,9 +61,6 @@ QT_BEGIN_NAMESPACE
namespace Qt3DCore {
-template <typename T, uint INDEXBITS>
-class QHandleManager;
-
template <typename T, uint INDEXBITS = 16>
class QHandle
{
@@ -82,18 +80,6 @@ public:
static quint32 maxIndex() { return MaxIndex; }
static quint32 maxCounter() { return MaxCounter; }
-
-private:
- enum {
- // Sizes to use for bit fields
- IndexBits = INDEXBITS,
- CounterBits = 32 - INDEXBITS - 2, // We use 2 bits for book-keeping in QHandleManager
-
- // Sizes to compare against for asserting dereferences
- MaxIndex = (1 << IndexBits) - 1,
- MaxCounter = (1 << CounterBits) - 1
- };
-
QHandle(quint32 i, quint32 count)
{
d.m_index = i;
@@ -103,10 +89,17 @@ private:
Q_ASSERT(count < MaxCounter);
}
+ enum {
+ // Sizes to use for bit fields
+ IndexBits = INDEXBITS,
+ CounterBits = 32 - INDEXBITS - 2, // We use 2 bits for book-keeping in QHandleManager
- friend class QHandleManager<T, INDEXBITS>;
- friend class ::tst_Handle;
+ // Sizes to compare against for asserting dereferences
+ MaxIndex = (1 << IndexBits) - 1,
+ MaxCounter = ((1 << CounterBits) - 1 > SHRT_MAX) ? SHRT_MAX - 1 : (1 << CounterBits) - 1
+ };
+private:
struct Data {
quint32 m_index : IndexBits;
quint32 m_counter : CounterBits;
diff --git a/src/core/resources/qhandlemanager_p.h b/src/core/resources/qhandlemanager_p.h
deleted file mode 100644
index 0c3609bb9..000000000
--- a/src/core/resources/qhandlemanager_p.h
+++ /dev/null
@@ -1,263 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QT3DCORE_QHANDLEMANAGER_P_H
-#define QT3DCORE_QHANDLEMANAGER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <Qt3DCore/qt3dcore_global.h>
-#include <QtCore/QtGlobal>
-#include <QtCore/QVector>
-
-#include <Qt3DCore/private/qhandle_p.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DCore {
-
-#ifndef QT_NO_DEBUG_STREAM
-template <typename T, uint INDEXBITS>
-class QHandleManager;
-
-template <typename T, uint INDEXBITS = 16>
-QDebug operator<<(QDebug dbg, const QHandleManager<T, INDEXBITS> &manager);
-#endif
-
-template <typename T, uint INDEXBITS = 16>
-class QHandleManager
-{
-public:
- QHandleManager()
- : m_firstFreeEntry(0)
- , m_activeEntryCount(0)
- , m_entries(1 << INDEXBITS)
- {
- reset();
- }
-
- quint32 activeEntries() const { return m_activeEntryCount; }
-
- void reset();
- QHandle<T, INDEXBITS> acquire(T *d);
- void release(const QHandle<T, INDEXBITS> &handle);
- void update(const QHandle<T, INDEXBITS> &, T *d);
- T *data(const QHandle<T, INDEXBITS> &handle, bool *ok = 0);
- const T *constData(const QHandle<T, INDEXBITS> &handle, bool *ok = 0) const;
- QVector<T *> entries() const;
-
-private:
- Q_DISABLE_COPY(QHandleManager)
-
- friend QDebug operator<< <>(QDebug dbg, const QHandleManager<T, INDEXBITS> &manager);
-
- template <typename U>
- struct HandleEntry
- {
- HandleEntry()
- : m_data(nullptr)
- , m_nextFreeIndex(0)
- , m_counter(0)
- , m_active(false)
- , m_endOfFreeList(false)
- {}
-
- explicit HandleEntry(quint32 nextFreeIndex)
- : m_data(nullptr)
- , m_nextFreeIndex(nextFreeIndex)
- , m_counter(0)
- , m_active(false)
- , m_endOfFreeList(false)
- {}
-
- U *m_data;
- unsigned int m_nextFreeIndex : QHandle<U, INDEXBITS>::IndexBits;
- unsigned int m_counter : QHandle<U, INDEXBITS>::CounterBits;
- unsigned int m_active : 1;
- unsigned int m_endOfFreeList : 1;
- };
-
- quint32 m_firstFreeEntry;
- int m_activeEntryCount;
- QVector<HandleEntry<T> > m_entries;
-};
-
-template <typename T, uint INDEXBITS>
-void QHandleManager<T, INDEXBITS>::reset()
-{
- m_activeEntryCount = 0;
- m_firstFreeEntry = 0;
-
- for (int i = 0; i < QHandle<T, INDEXBITS >::MaxIndex; ++i)
- m_entries[i] = HandleEntry<T>(i + 1);
- m_entries[QHandle<T, INDEXBITS>::MaxIndex] = HandleEntry<T>();
- m_entries[QHandle<T, INDEXBITS>::MaxIndex].m_endOfFreeList = true;
-}
-
-template <typename T, uint INDEXBITS>
-QHandle<T, INDEXBITS> QHandleManager<T, INDEXBITS>::acquire(T *d)
-{
- typedef QHandle<T, INDEXBITS> qHandle;
- Q_ASSERT(m_activeEntryCount < qHandle::MaxIndex);
-
- const quint32 newIndex = m_firstFreeEntry;
- Q_ASSERT(newIndex < qHandle::MaxIndex);
- Q_ASSERT(m_entries[newIndex].m_active == false);
- Q_ASSERT(!m_entries[newIndex].m_endOfFreeList);
-
- m_firstFreeEntry = m_entries[newIndex].m_nextFreeIndex;
- m_entries[newIndex].m_nextFreeIndex = 0;
- ++m_entries[newIndex].m_counter;
- // Check if the counter is about to overflow and reset if necessary
- if (m_entries[newIndex].m_counter == qHandle::MaxCounter)
- m_entries[newIndex].m_counter = 0;
- if (m_entries[newIndex].m_counter == 0)
- m_entries[newIndex].m_counter = 1;
- m_entries[newIndex].m_active = true;
- m_entries[newIndex].m_data = d;
-
- ++m_activeEntryCount;
-
- return qHandle(newIndex, m_entries[newIndex].m_counter);
-}
-
-template <typename T, uint INDEXBITS>
-void QHandleManager<T, INDEXBITS>::release(const QHandle<T, INDEXBITS> &handle)
-{
- const quint32 index = handle.index();
- Q_ASSERT(m_entries[index].m_counter == handle.counter());
- Q_ASSERT(m_entries[index].m_active == true);
-
- m_entries[index].m_nextFreeIndex = m_firstFreeEntry;
- m_entries[index].m_active = false;
- m_firstFreeEntry = index;
-
- --m_activeEntryCount;
-}
-
-// Needed in case the QResourceManager has reordered
-// memory so that the handle still points to valid data
-template <typename T, uint INDEXBITS>
-void QHandleManager<T, INDEXBITS>::update(const QHandle<T, INDEXBITS> &handle, T *d)
-{
- const quint32 index = handle.index();
- Q_ASSERT(m_entries[index].m_counter == handle.counter());
- Q_ASSERT(m_entries[index].m_active == true);
- m_entries[index].m_data = d;
-}
-
-template <typename T, uint INDEXBITS>
-T *QHandleManager<T, INDEXBITS>::data(const QHandle<T, INDEXBITS> &handle, bool *ok)
-{
- const quint32 index = handle.index();
- if (m_entries[index].m_counter != handle.counter() ||
- m_entries[index].m_active == false) {
- if (ok)
- *ok = false;
- return nullptr;
- }
-
- T *d = m_entries[index].m_data;
- if (ok)
- *ok = true;
- return d;
-}
-
-template <typename T, uint INDEXBITS>
-const T *QHandleManager<T, INDEXBITS>::constData(const QHandle<T, INDEXBITS> &handle, bool *ok) const
-{
- const quint32 index = handle.index();
- if (m_entries[index].m_counter != handle.counter() ||
- m_entries[index].m_active == false) {
- if (ok)
- *ok = false;
- return nullptr;
- }
-
- const T *d = m_entries[index].m_data;
- if (ok)
- *ok = true;
- return d;
-}
-
-#ifndef QT_NO_DEBUG_STREAM
-template <typename T, uint INDEXBITS>
-QDebug operator<<(QDebug dbg, const QHandleManager<T, INDEXBITS> &manager)
-{
- QDebugStateSaver saver(dbg);
- dbg << "First free entry =" << manager.m_firstFreeEntry << endl;
-
- const auto end = manager.m_entries.cend();
- const auto max = manager.m_activeEntryCount;
- auto i = 0;
- for (auto it = manager.m_entries.cbegin(); it != end && i < max; ++it) {
- const auto isActive = it->m_active;
- if (isActive) {
- dbg << *(it->m_data);
- ++i;
- }
- }
-
- return dbg;
-}
-#endif
-
-template <typename T, uint INDEXBITS>
-QVector<T *> QHandleManager<T, INDEXBITS>::entries() const
-{
- QVector<T *> entries;
- for (auto handle : qAsConst(m_entries))
- entries.append(handle.m_data);
- return entries;
-}
-
-} // Qt3D
-
-QT_END_NAMESPACE
-
-#endif // QT3DCORE_QHANDLEMANAGER_H
diff --git a/src/core/resources/qresourcemanager_p.h b/src/core/resources/qresourcemanager_p.h
index 0d8cdffbf..85233c97f 100644
--- a/src/core/resources/qresourcemanager_p.h
+++ b/src/core/resources/qresourcemanager_p.h
@@ -57,9 +57,9 @@
#include <QtCore/QReadLocker>
#include <QtCore/QReadWriteLock>
#include <QtCore/QtGlobal>
+#include <limits>
#include <Qt3DCore/private/qhandle_p.h>
-#include <Qt3DCore/private/qhandlemanager_p.h>
// Silence complaints about unreferenced local variables in
// ArrayAllocatingPolicy::deallocateBuckets() when the compiler
@@ -224,11 +224,12 @@ template <typename T, uint INDEXBITS = 16>
class ArrayAllocatingPolicy
{
public:
+ typedef QHandle<T, INDEXBITS> Handle;
ArrayAllocatingPolicy()
- : m_numBuckets(0)
- , m_numConstructed(0)
{
- reset();
+ m_freeList.resize(MaxSize);
+ for (int i = 0; i < MaxSize; i++)
+ m_freeList[i] = MaxSize - (i + 1);
}
~ArrayAllocatingPolicy()
@@ -236,7 +237,7 @@ public:
deallocateBuckets();
}
- T* allocateResource()
+ Handle allocateResource()
{
Q_ASSERT(!m_freeList.isEmpty());
int idx = m_freeList.takeLast();
@@ -245,9 +246,11 @@ public:
Q_ASSERT(bucketIdx <= m_numBuckets);
if (bucketIdx == m_numBuckets) {
m_bucketDataPtrs[bucketIdx] = static_cast<T*>(malloc(sizeof(T) * BucketSize));
+ m_counters[bucketIdx] = static_cast<short *>(malloc(sizeof(short) * BucketSize));
// ### memset is only needed as long as we also use this for primitive types (see FrameGraphManager)
// ### remove once this is fixed, add a static_assert on T instead
- memset((void*) m_bucketDataPtrs[bucketIdx], 0, sizeof(T) * BucketSize);
+ memset((void *)m_bucketDataPtrs[bucketIdx], 0, sizeof(T) * BucketSize);
+ memset(m_counters[bucketIdx], 0, sizeof(short) * BucketSize);
++m_numBuckets;
}
@@ -256,39 +259,47 @@ public:
new (m_bucketDataPtrs[bucketIdx] + localIdx) T;
++m_numConstructed;
}
-
- return m_bucketDataPtrs[bucketIdx] + localIdx;
+ Q_STATIC_ASSERT(Handle::MaxCounter < USHRT_MAX);
+ Q_ASSERT(m_counters[bucketIdx][localIdx] <= 0);
+ m_counters[bucketIdx][localIdx] *= -1;
+ ++m_counters[bucketIdx][localIdx];
+ if (m_counters[bucketIdx][localIdx] >= Handle::MaxCounter)
+ m_counters[bucketIdx][localIdx] = 1;
+
+ return Handle(idx, m_counters[bucketIdx][localIdx]);
}
- void releaseResource(T *r)
+ void releaseResource(Handle h)
{
- // search linearly over buckets to find the index of the resource
- // and put it into the free list
- for (int bucketIdx = 0; bucketIdx < m_numBuckets; ++bucketIdx) {
- const T* firstItem = m_bucketDataPtrs[bucketIdx];
- if (firstItem > r || r >= firstItem + BucketSize) {
- // resource is not in this bucket when its pointer address
- // is outside the address range spanned by the addresses of
- // the first and last items in a bucket
- continue;
- }
+ int idx = h.index();
+ int bucketIdx = idx / BucketSize;
+ int localIdx = idx % BucketSize;
+
+ Q_ASSERT(h.counter() == static_cast<quint32>(m_counters[bucketIdx][localIdx]));
+ T *r = m_bucketDataPtrs[bucketIdx] + localIdx;
+
+ m_freeList.append(idx);
+ m_counters[bucketIdx][localIdx] *= -1;
+ performCleanup(r, Int2Type<QResourceInfo<T>::needsCleanup>());
+ }
+
+ T *data(Handle h/*, bool *ok = 0*/) {
+ int bucketIdx = h.index() / BucketSize;
+ int localIdx = h.index() % BucketSize;
- // now we found the bucket we can reconstruct the global index
- // and put it back into the free list
- const int localIdx = static_cast<int>(r - firstItem);
- const int idx = bucketIdx * BucketSize + localIdx;
- m_freeList.append(idx);
- performCleanup(r, Int2Type<QResourceInfo<T>::needsCleanup>());
- break;
+ if (h.counter() != static_cast<quint32>(m_counters[bucketIdx][localIdx])) {
+ return nullptr;
}
+ return m_bucketDataPtrs[bucketIdx] + localIdx;
}
- void reset()
- {
- deallocateBuckets();
- m_freeList.resize(MaxSize);
- for (int i = 0; i < MaxSize; i++)
- m_freeList[i] = MaxSize - (i + 1);
+ void for_each(std::function<void(T*)> f) {
+ for (int idx = 0; idx < m_numConstructed; ++idx) {
+ int bucketIdx = idx / BucketSize;
+ int localIdx = idx % BucketSize;
+ T * t = m_bucketDataPtrs[bucketIdx] + localIdx;
+ f(t);
+ }
}
private:
@@ -313,13 +324,15 @@ private:
while (m_numBuckets > 0) {
--m_numBuckets;
free(m_bucketDataPtrs[m_numBuckets]);
+ free(m_counters[m_numBuckets]);
}
}
T* m_bucketDataPtrs[MaxSize / BucketSize];
+ short *m_counters[MaxSize / BucketSize];
QVector<int> m_freeList;
- int m_numBuckets;
- int m_numConstructed;
+ int m_numBuckets = 0;
+ int m_numConstructed = 0;
void performCleanup(T *r, Int2Type<true>)
{
@@ -354,8 +367,11 @@ class QResourceManager
, public LockingPolicy< QResourceManager<ValueType, KeyType, INDEXBITS, AllocatingPolicy, LockingPolicy> >
{
public:
+ typedef AllocatingPolicy<ValueType, INDEXBITS> Allocator;
+ typedef QHandle<ValueType, INDEXBITS> Handle;
+
QResourceManager() :
- AllocatingPolicy<ValueType, INDEXBITS>(),
+ Allocator(),
m_maxSize((1 << INDEXBITS) - 1)
{
}
@@ -363,52 +379,43 @@ public:
~QResourceManager()
{}
- QHandle<ValueType, INDEXBITS> acquire()
+ Handle acquire()
{
typename LockingPolicy<QResourceManager>::WriteLocker lock(this);
- QHandle<ValueType, INDEXBITS> handle = m_handleManager.acquire(AllocatingPolicy<ValueType, INDEXBITS>::allocateResource());
+ Handle handle = Allocator::allocateResource();
m_activeHandles.push_back(handle);
return handle;
}
- ValueType* data(const QHandle<ValueType, INDEXBITS> &handle)
+ ValueType* data(const Handle &handle)
{
typename LockingPolicy<QResourceManager>::ReadLocker lock(this);
- ValueType* d = m_handleManager.data(handle);
- return d;
+ return Allocator::data(handle);
}
- void release(const QHandle<ValueType, INDEXBITS> &handle)
+ void release(const Handle &handle)
{
typename LockingPolicy<QResourceManager>::WriteLocker lock(this);
releaseLocked(handle);
}
- void reset()
- {
- typename LockingPolicy<QResourceManager>::WriteLocker lock(this);
- m_handleManager.reset();
- m_activeHandles.clear();
- AllocatingPolicy<ValueType, INDEXBITS>::reset();
- }
-
bool contains(const KeyType &id) const
{
typename LockingPolicy<QResourceManager>::ReadLocker lock(this);
return m_keyToHandleMap.contains(id);
}
- QHandle<ValueType, INDEXBITS> getOrAcquireHandle(const KeyType &id)
+ Handle getOrAcquireHandle(const KeyType &id)
{
typename LockingPolicy<QResourceManager>::ReadLocker lock(this);
- QHandle<ValueType, INDEXBITS> handle = m_keyToHandleMap.value(id);
+ Handle handle = m_keyToHandleMap.value(id);
if (handle.isNull()) {
lock.unlock();
typename LockingPolicy<QResourceManager>::WriteLocker writeLock(this);
// Test that the handle hasn't been set (in the meantime between the read unlock and the write lock)
- QHandle<ValueType, INDEXBITS> &handleToSet = m_keyToHandleMap[id];
+ Handle &handleToSet = m_keyToHandleMap[id];
if (handleToSet.isNull()) {
- handleToSet = m_handleManager.acquire(AllocatingPolicy<ValueType, INDEXBITS>::allocateResource());
+ handleToSet = Allocator::allocateResource();
m_activeHandles.push_back(handleToSet);
}
return handleToSet;
@@ -416,7 +423,7 @@ public:
return handle;
}
- QHandle<ValueType, INDEXBITS> lookupHandle(const KeyType &id)
+ Handle lookupHandle(const KeyType &id)
{
typename LockingPolicy<QResourceManager>::ReadLocker lock(this);
return m_keyToHandleMap.value(id);
@@ -427,47 +434,44 @@ public:
ValueType* ret = nullptr;
{
typename LockingPolicy<QResourceManager>::ReadLocker lock(this);
- QHandle<ValueType, INDEXBITS> handle = m_keyToHandleMap.value(id);
+ Handle handle = m_keyToHandleMap.value(id);
if (!handle.isNull())
- ret = m_handleManager.data(handle);
+ ret = Allocator::data(handle);
}
return ret;
}
ValueType *getOrCreateResource(const KeyType &id)
{
- const QHandle<ValueType, INDEXBITS> handle = getOrAcquireHandle(id);
+ const Handle handle = getOrAcquireHandle(id);
typename LockingPolicy<QResourceManager>::ReadLocker lock(this);
- return m_handleManager.data(handle);
+ return Allocator::data(handle);
}
void releaseResource(const KeyType &id)
{
typename LockingPolicy<QResourceManager>::WriteLocker lock(this);
- QHandle<ValueType, INDEXBITS> handle = m_keyToHandleMap.take(id);
+ Handle handle = m_keyToHandleMap.take(id);
if (!handle.isNull())
releaseLocked(handle);
}
int maximumSize() const { return m_maxSize; }
- int count() const Q_DECL_NOEXCEPT { return m_handleManager.activeEntries(); }
+ int count() const Q_DECL_NOEXCEPT { return m_activeHandles.size(); }
- inline QVector<QHandle<ValueType, INDEXBITS> > activeHandles() const Q_DECL_NOEXCEPT { return m_activeHandles; }
+ inline QVector<Handle > activeHandles() const Q_DECL_NOEXCEPT { return m_activeHandles; }
protected:
- QHandleManager<ValueType, INDEXBITS> m_handleManager;
- QHash<KeyType, QHandle<ValueType, INDEXBITS> > m_keyToHandleMap;
- QVector<QHandle<ValueType, INDEXBITS> > m_activeHandles;
+ QHash<KeyType, Handle > m_keyToHandleMap;
+ QVector<Handle > m_activeHandles;
const int m_maxSize;
private:
- void releaseLocked(const QHandle<ValueType, INDEXBITS> &handle)
+ void releaseLocked(const Handle &handle)
{
- ValueType *val = m_handleManager.data(handle);
- m_handleManager.release(handle);
m_activeHandles.removeOne(handle);
- AllocatingPolicy<ValueType, INDEXBITS>::releaseResource(val);
+ Allocator::releaseResource(handle);
}
friend QDebug operator<< <>(QDebug dbg, const QResourceManager<ValueType, KeyType, INDEXBITS, AllocatingPolicy, LockingPolicy> &manager);
@@ -488,8 +492,8 @@ QDebug operator<<(QDebug dbg, const QResourceManager<ValueType, KeyType, INDEXBI
for (auto it = manager.m_keyToHandleMap.cbegin(); it != end; ++it)
dbg << "QNodeId =" << it.key() << "Handle =" << it.value() << endl;
- dbg << "Resources:" << endl;
- dbg << manager.m_handleManager;
+// dbg << "Resources:" << endl;
+// dbg << manager.m_handleManager;
return dbg;
}
#endif
diff --git a/src/core/resources/resources.pri b/src/core/resources/resources.pri
index 855d73b79..96ea21e93 100644
--- a/src/core/resources/resources.pri
+++ b/src/core/resources/resources.pri
@@ -1,5 +1,4 @@
HEADERS += \
- $$PWD/qhandlemanager_p.h \
$$PWD/qresourcemanager_p.h \
$$PWD/qcircularbuffer_p.h \
$$PWD/qboundedcircularbuffer_p.h \
diff --git a/src/render/backend/managers_p.h b/src/render/backend/managers_p.h
index 1c1a34b83..53d5e61c0 100644
--- a/src/render/backend/managers_p.h
+++ b/src/render/backend/managers_p.h
@@ -142,11 +142,10 @@ public:
EntityManager() {}
~EntityManager()
{
- const auto entries = m_handleManager.entries();
- for (Entity *e : entries) {
+ Allocator::for_each([](Entity *e) {
if (e)
e->setNodeManagers(nullptr);
- }
+ });
}
};
diff --git a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp b/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp
index 874ac42ca..5c193ec90 100644
--- a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp
+++ b/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp
@@ -44,7 +44,6 @@ private slots:
void getResources();
void registerResourcesResize();
void removeResource();
- void resetResource();
void lookupResource();
void releaseResource();
void heavyDutyMultiThreadedAccess();
@@ -187,36 +186,6 @@ void tst_DynamicArrayPolicy::removeResource()
QVERIFY(manager.data(nHandle) != nullptr);
}
-/*!
- * Checks that reset behaves correctly.
- */
-void tst_DynamicArrayPolicy::resetResource()
-{
- Qt3DCore::QResourceManager<tst_ArrayResource, uint> manager;
-
- QList<tst_ArrayResource *> resources;
- QList<tHandle16> handles;
-
- for (int i = 0; i < 5; i++) {
- handles << manager.acquire();
- resources << manager.data(handles.at(i));
- resources.at(i)->m_value = 4;
- }
- manager.reset();
- for (uint i = 0; i < 5; i++) {
- QVERIFY(manager.data(handles.at(i)) == nullptr);
- }
- handles.clear();
- for (uint i = 0; i < 5; i++)
- handles << manager.acquire();
-
- for (uint i = 0; i < 5; i++) {
- QVERIFY(handles.at(i).index() == i);
- QVERIFY(handles.at(i).counter() == 1);
- QVERIFY(manager.data(handles.at(i))->m_value != 4);
- }
-}
-
void tst_DynamicArrayPolicy::lookupResource()
{
Qt3DCore::QResourceManager<tst_ArrayResource, uint> manager;
diff --git a/tests/auto/core/core.pro b/tests/auto/core/core.pro
index 637ee086e..088940b7d 100644
--- a/tests/auto/core/core.pro
+++ b/tests/auto/core/core.pro
@@ -2,7 +2,6 @@ TEMPLATE = subdirs
SUBDIRS = \
handle \
- handlemanager \
arrayresourcesmanager \
qcircularbuffer \
qboundedcircularbuffer \
diff --git a/tests/auto/core/handlemanager/handlemanager.pro b/tests/auto/core/handlemanager/handlemanager.pro
deleted file mode 100644
index ad18d5b9b..000000000
--- a/tests/auto/core/handlemanager/handlemanager.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-TARGET = tst_handlemanager
-CONFIG += testcase
-TEMPLATE = app
-
-SOURCES += tst_handlemanager.cpp
-
-QT += testlib 3dcore 3dcore-private
diff --git a/tests/auto/core/handlemanager/tst_handlemanager.cpp b/tests/auto/core/handlemanager/tst_handlemanager.cpp
deleted file mode 100644
index f4879a3df..000000000
--- a/tests/auto/core/handlemanager/tst_handlemanager.cpp
+++ /dev/null
@@ -1,306 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <Qt3DCore/private/qhandlemanager_p.h>
-#include <Qt3DCore/private/qhandle_p.h>
-
-class tst_HandleManager : public QObject
-{
- Q_OBJECT
-public:
- tst_HandleManager() {}
- ~tst_HandleManager() {}
-
-private slots:
- void construction();
- void correctPointer();
- void correctPointers();
- void correctConstPointer();
- void nullForRemovedEntry();
- void validHandleForReplacementEntry();
- void updateChangesValue();
- void resetRemovesAllEntries();
- void maximumEntries();
- void checkNoCounterOverflow();
-};
-
-class SimpleResource
-{
-public:
- SimpleResource()
- : m_value(0)
- {}
-
- int m_value;
-};
-
-typedef Qt3DCore::QHandle<SimpleResource> Handle;
-
-void tst_HandleManager::construction()
-{
- // GIVEN
- Qt3DCore::QHandleManager<SimpleResource> manager;
-
- // THEN
- QVERIFY(manager.activeEntries() == 0);
-}
-
-void tst_HandleManager::correctPointer()
-{
- // GIVEN
- Qt3DCore::QHandleManager<SimpleResource> manager;
- SimpleResource *p1 = (SimpleResource *)(quintptr)0xdeadbeef;
-
- // WHEN
- const Handle h = manager.acquire(p1);
-
- bool ok = false;
- SimpleResource *p2 = manager.data(h, &ok);
-
- // THEN
- QVERIFY(ok == true);
- QVERIFY(p1 == p2);
-}
-
-void tst_HandleManager::correctPointers()
-{
- // GIVEN
- Qt3DCore::QHandleManager<SimpleResource> manager;
- SimpleResource *p[3];
- p[0] = (SimpleResource *)(quintptr)0xdeadbeef;
- p[1] = (SimpleResource *)(quintptr)0x11111111;
- p[2] = (SimpleResource *)(quintptr)0x22222222;
-
- // WHEN
- for (int i = 0; i < 3; ++i) {
- // WHEN
- const Handle h = manager.acquire(p[i]);
-
- bool ok = false;
- SimpleResource *q = manager.data(h, &ok);
-
- // THEN
- QVERIFY(ok == true);
- QVERIFY(p[i] == q);
- }
-
- // THEN
- QVERIFY(manager.activeEntries() == 3);
-}
-
-void tst_HandleManager::correctConstPointer()
-{
- // GIVEN
- Qt3DCore::QHandleManager<SimpleResource> manager;
- QSharedPointer<SimpleResource> p1(new SimpleResource);
- const Handle h = manager.acquire(p1.data());
-
- // WHEN
- bool ok = false;
- const SimpleResource *p2 = manager.constData(h, &ok);
-
- // THEN
- QVERIFY(ok == true);
- QVERIFY(p1.data() == p2);
-}
-
-void tst_HandleManager::nullForRemovedEntry()
-{
- // GIVEN
- Qt3DCore::QHandleManager<SimpleResource> manager;
- QSharedPointer<SimpleResource> p1(new SimpleResource);
- const Handle h = manager.acquire(p1.data());
-
- // WHEN
- manager.release(h);
-
- // THEN
- bool ok = false;
- SimpleResource *p2 = manager.data(h, &ok);
- QVERIFY(ok == false);
- QVERIFY(p2 == nullptr);
-}
-
-void tst_HandleManager::validHandleForReplacementEntry()
-{
- // GIVEN
- Qt3DCore::QHandleManager<SimpleResource> manager;
- QSharedPointer<SimpleResource> p1(new SimpleResource);
- const Handle h = manager.acquire(p1.data());
-
- // THEN
- QVERIFY(manager.activeEntries() == 1);
-
- // WHEN
- manager.release(h);
-
- // THEN
- QVERIFY(manager.activeEntries() == 0);
-
- // WHEN
- QSharedPointer<SimpleResource> p2(new SimpleResource);
- const Handle h2 = manager.acquire(p2.data());
-
- // THEN
- QVERIFY(h2.isNull() == false);
- QVERIFY(h2.counter() == 2);
- QVERIFY(manager.activeEntries() == 1);
-
- // WHEN
- bool ok = false;
- SimpleResource *p3 = manager.data(h2, &ok);
-
- // THEN
- QVERIFY(ok == true);
- QVERIFY(p3 == p2);
-}
-
-void tst_HandleManager::updateChangesValue()
-{
- // GIVEN
- Qt3DCore::QHandleManager<SimpleResource> manager;
- QSharedPointer<SimpleResource> p1(new SimpleResource);
- const Handle h = manager.acquire(p1.data());
-
- // WHEN
- QSharedPointer<SimpleResource> p2(new SimpleResource);
- manager.update(h, p2.data());
-
- // THEN
- QVERIFY(manager.activeEntries() == 1);
-
- // WHEN
- bool ok = false;
- SimpleResource *p3 = manager.data(h, &ok);
-
- // THEN
- QVERIFY(ok == true);
- QVERIFY(p3 == p2);
-}
-
-void tst_HandleManager::resetRemovesAllEntries()
-{
- // GIVEN
- Qt3DCore::QHandleManager<SimpleResource> manager;
-
- // WHEN
- for (int i = 0; i < 100; ++i) {
- SimpleResource *p = (SimpleResource *)(quintptr)(0xdead0000 + i);
- const Handle h = manager.acquire(p);
-
- bool ok = false;
- SimpleResource *q = manager.data(h, &ok);
- QVERIFY(ok == true);
- QVERIFY(p == q);
- }
-
- // THEN
- QVERIFY(manager.activeEntries() == 100);
-
- // WHEN
- manager.reset();
-
- // THEN
- QVERIFY(manager.activeEntries() == 0);
-}
-
-void tst_HandleManager::maximumEntries()
-{
- // GIVEN
- Qt3DCore::QHandleManager<SimpleResource> manager;
-
- // THEN
- QCOMPARE(Handle::maxIndex(), (uint)((1 << 16) - 1));
-
- // WHEN
- for (int i = 0; i < (int)Handle::maxIndex(); ++i) {
- SimpleResource *p = (SimpleResource *)(quintptr)(0xdead0000 + i);
- const Handle h = manager.acquire(p);
-
- bool ok = false;
- SimpleResource *q = manager.data(h, &ok);
- QVERIFY(ok == true);
- QVERIFY(p == q);
- }
-
- // THEN
- QVERIFY(manager.activeEntries() == Handle::maxIndex());\
-
- // WHEN
- manager.reset();
-
- // THEN
- QVERIFY(manager.activeEntries() == 0);
-}
-
-void tst_HandleManager::checkNoCounterOverflow()
-{
- // GIVEN
- const int indexBits = 16;
- Qt3DCore::QHandleManager<SimpleResource, indexBits> manager;
- SimpleResource *p = (SimpleResource *)(quintptr)0xdead0000;
- Qt3DCore::QHandle<SimpleResource, indexBits> h = manager.acquire(p);
-
- // THEN
- QCOMPARE(h.maxCounter(), (quint32)((1 << (32 - indexBits - 2)) - 1));
- QCOMPARE(h.counter(), (quint32)1);
-
- // WHEN
- const quint32 maxIterations = h.maxCounter() - 2;
- const quint32 handleIndex = h.index();
-
- qDebug() << maxIterations << handleIndex;
-
- // Acquire and release maxIteration time to increase counter
- for (quint32 i = 0; i < maxIterations; ++i) {
- // WHEN
- manager.release(h);
- h = manager.acquire(p);
-
- // THEN
- QCOMPARE(h.index(), handleIndex);
- QCOMPARE(h.counter(), i + 2);
- }
-
- // THEN
- QCOMPARE(h.counter(), h.maxCounter() - 1);
-
- // WHEN
- manager.release(h);
- h = manager.acquire(p);
-
- // THEN
- QCOMPARE(h.counter(), (quint32)1);
-}
-
-
-
-QTEST_APPLESS_MAIN(tst_HandleManager)
-
-#include "tst_handlemanager.moc"
diff --git a/tests/benchmarks/core/qresourcesmanager/arraypolicy/tst_bench_arraypolicy.cpp b/tests/benchmarks/core/qresourcesmanager/arraypolicy/tst_bench_arraypolicy.cpp
index 0b4587ae8..0813fff91 100644
--- a/tests/benchmarks/core/qresourcesmanager/arraypolicy/tst_bench_arraypolicy.cpp
+++ b/tests/benchmarks/core/qresourcesmanager/arraypolicy/tst_bench_arraypolicy.cpp
@@ -69,7 +69,7 @@ void benchmarkReleaseResources()
Qt3DCore::ArrayAllocatingPolicy<T> allocator;
const int max = (1 << 16) - 1;
- QVector<T *> resources(max);
+ QVector<Qt3DCore::QHandle<T>> resources(max);
for (int i = 0; i < max; i++) {
resources[i] = allocator.allocateResource();
}
diff --git a/tests/benchmarks/core/qresourcesmanager/qresourcesmanager/tst_bench_qresourcesmanager.cpp b/tests/benchmarks/core/qresourcesmanager/qresourcesmanager/tst_bench_qresourcesmanager.cpp
index 48b12b5f2..6ddb058a1 100644
--- a/tests/benchmarks/core/qresourcesmanager/qresourcesmanager/tst_bench_qresourcesmanager.cpp
+++ b/tests/benchmarks/core/qresourcesmanager/qresourcesmanager/tst_bench_qresourcesmanager.cpp
@@ -161,7 +161,7 @@ void benchmarkReleaseResources()
handles[i] = manager.acquire();
QBENCHMARK_ONCE {
- manager.reset();
+ /*manager.reset()*/;
}
}