1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40/* !\internal
41 \class Qt3DCore::QResourceManager
42 \inmodule Qt3DCore
43 \since 5.5
44
45 \brief The QResourceManager allocates memory for resources that can be referenced by a QHandle.
46
47 Using a QHandleManager for handle management, the QResourceManager's responsibility is
48 to provide memory for resources and to offer ways to interact with the resource through
49 the QHandle.
50
51 Using the QHandle obtained when acquiring a resource, the resource can be retrieved and
52 released when no longer needed.
53
54 Internally, memory can be reorganized for best performance while being transparent to the user.
55
56 The memory allocation scheme and locking policies can be customized by providing template
57 parameters. The defaults are ArrayAllocatingPolicy and NonLockingPolicy respectively.
58*/
59
60/* !\internal
61 \class Qt3DCore::ArrayAllocatingPolicy
62 \inmodule Qt3DCore
63 \since 5.5
64
65 \brief Allocates memory in a contiguous space trying to minimize fragmentation and cache misses.
66
67 Once the maximum number of entities is reached, no more allocations can be made until some resources are
68 released
69
70 \sa QResourceManager
71*/
72
73/* !\internal
74 \class Qt3DCore::ObjectLevelLockingPolicy
75 \inmodule Qt3DCore
76 \since 5.5
77
78 \brief Provides locking access to a resource through the use of a QReadWriteLock.
79
80 This policy should be used in a QResourceManager when multiple threads may access the manager for
81 read and write operations at the same time.
82
83 It provides two convenience classes WriteLocker and ReadLocker that behave like QReadLocker and QWriteLocker.
84*/
85
86#include "qresourcemanager_p.h"
87#include <QtCore/private/qsimd_p.h>
88#include <Qt3DCore/private/qt3dcore-config_p.h>
89
90QT_BEGIN_NAMESPACE
91
92namespace Qt3DCore {
93
94void *AlignedAllocator::allocate(uint size)
95{
96#if QT_CONFIG(qt3d_simd_avx2) && defined(__AVX2__) && defined(QT_COMPILER_SUPPORTS_AVX2)
97 return _mm_malloc(size, 32);
98#elif QT_CONFIG(qt3d_simd_sse2) && defined(__SSE2__) && defined(QT_COMPILER_SUPPORTS_SSE2)
99 return _mm_malloc(size, 16);
100#else
101 return malloc(size);
102#endif
103}
104
105void AlignedAllocator::release(void *p)
106{
107#if QT_CONFIG(qt3d_simd_avx2) && defined(__AVX2__) && defined(QT_COMPILER_SUPPORTS_AVX2)
108 _mm_free(p);
109#elif QT_CONFIG(qt3d_simd_sse2) && defined(__SSE2__) && defined(QT_COMPILER_SUPPORTS_SSE2)
110 _mm_free(p);
111#else
112 free(p);
113#endif
114}
115
116} // Qt3DCore
117
118QT_END_NAMESPACE
119