Browse Source
[fs] remove usage of subpar PooledBuffer (#342)
[fs] remove usage of subpar PooledBuffer (#342)
PoolBuffer is a subpar "reimplementation" of an equivalent std::vector<char> Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/342 Reviewed-by: crueter <crueter@eden-emu.dev> Reviewed-by: Shinmegumi <shinmegumi@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>pull/315/head
committed by
crueter
No known key found for this signature in database
GPG Key ID: 425ACD2D4830EBC6
9 changed files with 54 additions and 271 deletions
-
3src/core/CMakeLists.txt
-
30src/core/file_sys/fssystem/fssystem_aes_ctr_storage.cpp
-
16src/core/file_sys/fssystem/fssystem_aes_xts_storage.cpp
-
28src/core/file_sys/fssystem/fssystem_alignment_matching_storage.h
-
24src/core/file_sys/fssystem/fssystem_bucket_tree.cpp
-
32src/core/file_sys/fssystem/fssystem_bucket_tree_template_impl.h
-
36src/core/file_sys/fssystem/fssystem_compressed_storage.h
-
61src/core/file_sys/fssystem/fssystem_pooled_buffer.cpp
-
95src/core/file_sys/fssystem/fssystem_pooled_buffer.h
@ -1,61 +0,0 @@ |
|||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||
|
|
||||
#include "common/alignment.h"
|
|
||||
#include "core/file_sys/fssystem/fssystem_pooled_buffer.h"
|
|
||||
|
|
||||
namespace FileSys { |
|
||||
|
|
||||
namespace { |
|
||||
|
|
||||
constexpr size_t HeapBlockSize = BufferPoolAlignment; |
|
||||
static_assert(HeapBlockSize == 4_KiB); |
|
||||
|
|
||||
// A heap block is 4KiB. An order is a power of two.
|
|
||||
// This gives blocks of the order 32KiB, 512KiB, 4MiB.
|
|
||||
constexpr s32 HeapOrderMax = 7; |
|
||||
constexpr s32 HeapOrderMaxForLarge = HeapOrderMax + 3; |
|
||||
|
|
||||
constexpr size_t HeapAllocatableSizeMax = HeapBlockSize * (static_cast<size_t>(1) << HeapOrderMax); |
|
||||
constexpr size_t HeapAllocatableSizeMaxForLarge = |
|
||||
HeapBlockSize * (static_cast<size_t>(1) << HeapOrderMaxForLarge); |
|
||||
|
|
||||
} // namespace
|
|
||||
|
|
||||
size_t PooledBuffer::GetAllocatableSizeMaxCore(bool large) { |
|
||||
return large ? HeapAllocatableSizeMaxForLarge : HeapAllocatableSizeMax; |
|
||||
} |
|
||||
|
|
||||
void PooledBuffer::AllocateCore(size_t ideal_size, size_t required_size, bool large) { |
|
||||
// Ensure preconditions.
|
|
||||
ASSERT(m_buffer == nullptr); |
|
||||
|
|
||||
// Check that we can allocate this size.
|
|
||||
ASSERT(required_size <= GetAllocatableSizeMaxCore(large)); |
|
||||
|
|
||||
const size_t target_size = |
|
||||
(std::min)((std::max)(ideal_size, required_size), GetAllocatableSizeMaxCore(large)); |
|
||||
|
|
||||
// Dummy implementation for allocate.
|
|
||||
if (target_size > 0) { |
|
||||
m_buffer = |
|
||||
reinterpret_cast<char*>(::operator new(target_size, std::align_val_t{HeapBlockSize})); |
|
||||
m_size = target_size; |
|
||||
|
|
||||
// Ensure postconditions.
|
|
||||
ASSERT(m_buffer != nullptr); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
void PooledBuffer::Shrink(size_t ideal_size) { |
|
||||
ASSERT(ideal_size <= GetAllocatableSizeMaxCore(true)); |
|
||||
|
|
||||
// Shrinking to zero means that we have no buffer.
|
|
||||
if (ideal_size == 0) { |
|
||||
::operator delete(m_buffer, std::align_val_t{HeapBlockSize}); |
|
||||
m_buffer = nullptr; |
|
||||
m_size = ideal_size; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} // namespace FileSys
|
|
||||
@ -1,95 +0,0 @@ |
|||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project |
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
|
|
||||
#pragma once |
|
||||
|
|
||||
#include "common/common_funcs.h" |
|
||||
#include "common/common_types.h" |
|
||||
#include "common/literals.h" |
|
||||
#include "core/hle/result.h" |
|
||||
|
|
||||
namespace FileSys { |
|
||||
|
|
||||
using namespace Common::Literals; |
|
||||
|
|
||||
constexpr inline size_t BufferPoolAlignment = 4_KiB; |
|
||||
constexpr inline size_t BufferPoolWorkSize = 320; |
|
||||
|
|
||||
class PooledBuffer { |
|
||||
YUZU_NON_COPYABLE(PooledBuffer); |
|
||||
|
|
||||
public: |
|
||||
// Constructor/Destructor. |
|
||||
constexpr PooledBuffer() : m_buffer(), m_size() {} |
|
||||
|
|
||||
PooledBuffer(size_t ideal_size, size_t required_size) : m_buffer(), m_size() { |
|
||||
this->Allocate(ideal_size, required_size); |
|
||||
} |
|
||||
|
|
||||
~PooledBuffer() { |
|
||||
this->Deallocate(); |
|
||||
} |
|
||||
|
|
||||
// Move and assignment. |
|
||||
explicit PooledBuffer(PooledBuffer&& rhs) : m_buffer(rhs.m_buffer), m_size(rhs.m_size) { |
|
||||
rhs.m_buffer = nullptr; |
|
||||
rhs.m_size = 0; |
|
||||
} |
|
||||
|
|
||||
PooledBuffer& operator=(PooledBuffer&& rhs) { |
|
||||
PooledBuffer(std::move(rhs)).Swap(*this); |
|
||||
return *this; |
|
||||
} |
|
||||
|
|
||||
// Allocation API. |
|
||||
void Allocate(size_t ideal_size, size_t required_size) { |
|
||||
return this->AllocateCore(ideal_size, required_size, false); |
|
||||
} |
|
||||
|
|
||||
void AllocateParticularlyLarge(size_t ideal_size, size_t required_size) { |
|
||||
return this->AllocateCore(ideal_size, required_size, true); |
|
||||
} |
|
||||
|
|
||||
void Shrink(size_t ideal_size); |
|
||||
|
|
||||
void Deallocate() { |
|
||||
// Shrink the buffer to empty. |
|
||||
this->Shrink(0); |
|
||||
ASSERT(m_buffer == nullptr); |
|
||||
} |
|
||||
|
|
||||
char* GetBuffer() const { |
|
||||
ASSERT(m_buffer != nullptr); |
|
||||
return m_buffer; |
|
||||
} |
|
||||
|
|
||||
size_t GetSize() const { |
|
||||
ASSERT(m_buffer != nullptr); |
|
||||
return m_size; |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
static size_t GetAllocatableSizeMax() { |
|
||||
return GetAllocatableSizeMaxCore(false); |
|
||||
} |
|
||||
static size_t GetAllocatableParticularlyLargeSizeMax() { |
|
||||
return GetAllocatableSizeMaxCore(true); |
|
||||
} |
|
||||
|
|
||||
private: |
|
||||
static size_t GetAllocatableSizeMaxCore(bool large); |
|
||||
|
|
||||
private: |
|
||||
void Swap(PooledBuffer& rhs) { |
|
||||
std::swap(m_buffer, rhs.m_buffer); |
|
||||
std::swap(m_size, rhs.m_size); |
|
||||
} |
|
||||
|
|
||||
void AllocateCore(size_t ideal_size, size_t required_size, bool large); |
|
||||
|
|
||||
private: |
|
||||
char* m_buffer; |
|
||||
size_t m_size; |
|
||||
}; |
|
||||
|
|
||||
} // namespace FileSys |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue