| 1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | /* !\internal |
| 5 | \class Qt3DCore::QResourceManager |
| 6 | \inmodule Qt3DCore |
| 7 | \since 5.5 |
| 8 | |
| 9 | \brief The QResourceManager allocates memory for resources that can be referenced by a QHandle. |
| 10 | |
| 11 | Using a QHandleManager for handle management, the QResourceManager's responsibility is |
| 12 | to provide memory for resources and to offer ways to interact with the resource through |
| 13 | the QHandle. |
| 14 | |
| 15 | Using the QHandle obtained when acquiring a resource, the resource can be retrieved and |
| 16 | released when no longer needed. |
| 17 | |
| 18 | Internally, memory can be reorganized for best performance while being transparent to the user. |
| 19 | |
| 20 | The memory allocation scheme and locking policies can be customized by providing template |
| 21 | parameters. The defaults are ArrayAllocatingPolicy and NonLockingPolicy respectively. |
| 22 | */ |
| 23 | |
| 24 | /* !\internal |
| 25 | \class Qt3DCore::ArrayAllocatingPolicy |
| 26 | \inmodule Qt3DCore |
| 27 | \since 5.5 |
| 28 | |
| 29 | \brief Allocates memory in a contiguous space trying to minimize fragmentation and cache misses. |
| 30 | |
| 31 | Once the maximum number of entities is reached, no more allocations can be made until some resources are |
| 32 | released |
| 33 | |
| 34 | \sa QResourceManager |
| 35 | */ |
| 36 | |
| 37 | /* !\internal |
| 38 | \class Qt3DCore::ObjectLevelLockingPolicy |
| 39 | \inmodule Qt3DCore |
| 40 | \since 5.5 |
| 41 | |
| 42 | \brief Provides locking access to a resource through the use of a QReadWriteLock. |
| 43 | |
| 44 | This policy should be used in a QResourceManager when multiple threads may access the manager for |
| 45 | read and write operations at the same time. |
| 46 | |
| 47 | It provides two convenience classes WriteLocker and ReadLocker that behave like QReadLocker and QWriteLocker. |
| 48 | */ |
| 49 | |
| 50 | #include "qresourcemanager_p.h" |
| 51 | #include <QtCore/private/qsimd_p.h> |
| 52 | #include <Qt3DCore/private/qt3dcore-config_p.h> |
| 53 | |
| 54 | QT_BEGIN_NAMESPACE |
| 55 | |
| 56 | namespace Qt3DCore { |
| 57 | |
| 58 | void *AlignedAllocator::allocate(uint size) |
| 59 | { |
| 60 | #if defined(__AVX2__) |
| 61 | return _mm_malloc(size, 32); |
| 62 | #elif defined(__SSE2__) |
| 63 | return _mm_malloc(size: size, align: 16); |
| 64 | #else |
| 65 | return malloc(size); |
| 66 | #endif |
| 67 | } |
| 68 | |
| 69 | void AlignedAllocator::release(void *p) |
| 70 | { |
| 71 | #if defined(__SSE2__) |
| 72 | _mm_free(p: p); |
| 73 | #else |
| 74 | free(p); |
| 75 | #endif |
| 76 | } |
| 77 | |
| 78 | } // Qt3DCore |
| 79 | |
| 80 | QT_END_NAMESPACE |
| 81 | |