| 1 | // Copyright (C) 2025 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QMEMORY_RESOURCE_TLSF_P_H |
| 5 | #define QMEMORY_RESOURCE_TLSF_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qtclasshelpermacros.h> |
| 19 | #include <QtMultimedia/private/q_pmr_emulation_p.h> |
| 20 | |
| 21 | #include <tlsf.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | namespace QtMultimediaPrivate { |
| 26 | |
| 27 | struct QTlsfMemoryResource final : pmr::memory_resource |
| 28 | { |
| 29 | explicit QTlsfMemoryResource(std::size_t preallocatedBytes, |
| 30 | pmr::memory_resource *upstream = pmr::get_default_resource()); |
| 31 | |
| 32 | Q_DISABLE_COPY_MOVE(QTlsfMemoryResource) |
| 33 | |
| 34 | ~QTlsfMemoryResource() override; |
| 35 | |
| 36 | private: |
| 37 | void *do_allocate(size_t bytes, size_t alignment) override; |
| 38 | void do_deallocate(void *p, size_t bytes, size_t alignment) override; |
| 39 | bool do_is_equal(const memory_resource &other) const noexcept override; |
| 40 | |
| 41 | // cache line alignment on most platforms |
| 42 | static constexpr auto poolAlignment = std::align_val_t{ 128 }; |
| 43 | |
| 44 | QtPrivate::tlsf_t m_tlsf; |
| 45 | const size_t m_allocationSize; |
| 46 | std::byte *m_buffer = nullptr; |
| 47 | pmr::memory_resource *m_upstream{}; |
| 48 | }; |
| 49 | |
| 50 | } // namespace QtMultimediaPrivate |
| 51 | |
| 52 | QT_END_NAMESPACE |
| 53 | |
| 54 | #endif // QMEMORY_RESOURCE_TLSF_P_H |
| 55 | |