diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio_core/renderer/adsp/audio_renderer.cpp | 8 | ||||
| -rw-r--r-- | src/audio_core/renderer/adsp/audio_renderer.h | 4 | ||||
| -rw-r--r-- | src/audio_core/sink/sink_stream.cpp | 5 | ||||
| -rw-r--r-- | src/audio_core/sink/sink_stream.h | 5 | ||||
| -rw-r--r-- | src/common/host_memory.cpp | 22 | ||||
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 5 | ||||
| -rw-r--r-- | src/core/file_sys/romfs.cpp | 3 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_cached.cpp | 63 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_cached.h | 31 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_vector.cpp | 19 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_vector.h | 4 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp_srv.cpp | 20 |
13 files changed, 147 insertions, 44 deletions
diff --git a/src/audio_core/renderer/adsp/audio_renderer.cpp b/src/audio_core/renderer/adsp/audio_renderer.cpp index 1cbeed302..8bc39f9f9 100644 --- a/src/audio_core/renderer/adsp/audio_renderer.cpp +++ b/src/audio_core/renderer/adsp/audio_renderer.cpp | |||
| @@ -105,7 +105,7 @@ void AudioRenderer::Start(AudioRenderer_Mailbox* mailbox_) { | |||
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | mailbox = mailbox_; | 107 | mailbox = mailbox_; |
| 108 | thread = std::thread(&AudioRenderer::ThreadFunc, this); | 108 | thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(stop_token); }); |
| 109 | running = true; | 109 | running = true; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| @@ -131,7 +131,7 @@ void AudioRenderer::CreateSinkStreams() { | |||
| 131 | } | 131 | } |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | void AudioRenderer::ThreadFunc() { | 134 | void AudioRenderer::ThreadFunc(std::stop_token stop_token) { |
| 135 | static constexpr char name[]{"AudioRenderer"}; | 135 | static constexpr char name[]{"AudioRenderer"}; |
| 136 | MicroProfileOnThreadCreate(name); | 136 | MicroProfileOnThreadCreate(name); |
| 137 | Common::SetCurrentThreadName(name); | 137 | Common::SetCurrentThreadName(name); |
| @@ -146,7 +146,7 @@ void AudioRenderer::ThreadFunc() { | |||
| 146 | 146 | ||
| 147 | constexpr u64 max_process_time{2'304'000ULL}; | 147 | constexpr u64 max_process_time{2'304'000ULL}; |
| 148 | 148 | ||
| 149 | while (true) { | 149 | while (!stop_token.stop_requested()) { |
| 150 | auto message{mailbox->ADSPWaitMessage()}; | 150 | auto message{mailbox->ADSPWaitMessage()}; |
| 151 | switch (message) { | 151 | switch (message) { |
| 152 | case RenderMessage::AudioRenderer_Shutdown: | 152 | case RenderMessage::AudioRenderer_Shutdown: |
| @@ -194,7 +194,7 @@ void AudioRenderer::ThreadFunc() { | |||
| 194 | max_time = std::min(command_buffer.time_limit, max_time); | 194 | max_time = std::min(command_buffer.time_limit, max_time); |
| 195 | command_list_processor.SetProcessTimeMax(max_time); | 195 | command_list_processor.SetProcessTimeMax(max_time); |
| 196 | 196 | ||
| 197 | streams[index]->WaitFreeSpace(); | 197 | streams[index]->WaitFreeSpace(stop_token); |
| 198 | 198 | ||
| 199 | // Process the command list | 199 | // Process the command list |
| 200 | { | 200 | { |
diff --git a/src/audio_core/renderer/adsp/audio_renderer.h b/src/audio_core/renderer/adsp/audio_renderer.h index 85ce6a269..88e558183 100644 --- a/src/audio_core/renderer/adsp/audio_renderer.h +++ b/src/audio_core/renderer/adsp/audio_renderer.h | |||
| @@ -177,7 +177,7 @@ private: | |||
| 177 | /** | 177 | /** |
| 178 | * Main AudioRenderer thread, responsible for processing the command lists. | 178 | * Main AudioRenderer thread, responsible for processing the command lists. |
| 179 | */ | 179 | */ |
| 180 | void ThreadFunc(); | 180 | void ThreadFunc(std::stop_token stop_token); |
| 181 | 181 | ||
| 182 | /** | 182 | /** |
| 183 | * Creates the streams which will receive the processed samples. | 183 | * Creates the streams which will receive the processed samples. |
| @@ -187,7 +187,7 @@ private: | |||
| 187 | /// Core system | 187 | /// Core system |
| 188 | Core::System& system; | 188 | Core::System& system; |
| 189 | /// Main thread | 189 | /// Main thread |
| 190 | std::thread thread{}; | 190 | std::jthread thread{}; |
| 191 | /// The current state | 191 | /// The current state |
| 192 | std::atomic<bool> running{}; | 192 | std::atomic<bool> running{}; |
| 193 | /// The active mailbox | 193 | /// The active mailbox |
diff --git a/src/audio_core/sink/sink_stream.cpp b/src/audio_core/sink/sink_stream.cpp index b408fca89..5d58b950c 100644 --- a/src/audio_core/sink/sink_stream.cpp +++ b/src/audio_core/sink/sink_stream.cpp | |||
| @@ -269,14 +269,15 @@ u64 SinkStream::GetExpectedPlayedSampleCount() { | |||
| 269 | return std::min<u64>(exp_played_sample_count, max_played_sample_count) + TargetSampleCount * 3; | 269 | return std::min<u64>(exp_played_sample_count, max_played_sample_count) + TargetSampleCount * 3; |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | void SinkStream::WaitFreeSpace() { | 272 | void SinkStream::WaitFreeSpace(std::stop_token stop_token) { |
| 273 | std::unique_lock lk{release_mutex}; | 273 | std::unique_lock lk{release_mutex}; |
| 274 | release_cv.wait_for(lk, std::chrono::milliseconds(5), | 274 | release_cv.wait_for(lk, std::chrono::milliseconds(5), |
| 275 | [this]() { return queued_buffers < max_queue_size; }); | 275 | [this]() { return queued_buffers < max_queue_size; }); |
| 276 | #ifndef ANDROID | 276 | #ifndef ANDROID |
| 277 | // This wait can cause a problematic shutdown hang on Android. | 277 | // This wait can cause a problematic shutdown hang on Android. |
| 278 | if (queued_buffers > max_queue_size + 3) { | 278 | if (queued_buffers > max_queue_size + 3) { |
| 279 | release_cv.wait(lk, [this]() { return queued_buffers < max_queue_size; }); | 279 | Common::CondvarWait(release_cv, lk, stop_token, |
| 280 | [this] { return queued_buffers < max_queue_size; }); | ||
| 280 | } | 281 | } |
| 281 | #endif | 282 | #endif |
| 282 | } | 283 | } |
diff --git a/src/audio_core/sink/sink_stream.h b/src/audio_core/sink/sink_stream.h index 21b5b40a1..41cbadc9c 100644 --- a/src/audio_core/sink/sink_stream.h +++ b/src/audio_core/sink/sink_stream.h | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | #include "audio_core/common/common.h" | 14 | #include "audio_core/common/common.h" |
| 15 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| 16 | #include "common/polyfill_thread.h" | ||
| 16 | #include "common/reader_writer_queue.h" | 17 | #include "common/reader_writer_queue.h" |
| 17 | #include "common/ring_buffer.h" | 18 | #include "common/ring_buffer.h" |
| 18 | #include "common/thread.h" | 19 | #include "common/thread.h" |
| @@ -210,7 +211,7 @@ public: | |||
| 210 | /** | 211 | /** |
| 211 | * Waits for free space in the sample ring buffer | 212 | * Waits for free space in the sample ring buffer |
| 212 | */ | 213 | */ |
| 213 | void WaitFreeSpace(); | 214 | void WaitFreeSpace(std::stop_token stop_token); |
| 214 | 215 | ||
| 215 | protected: | 216 | protected: |
| 216 | /// Core system | 217 | /// Core system |
| @@ -252,7 +253,7 @@ private: | |||
| 252 | /// Set via IAudioDevice service calls | 253 | /// Set via IAudioDevice service calls |
| 253 | f32 device_volume{1.0f}; | 254 | f32 device_volume{1.0f}; |
| 254 | /// Signalled when ring buffer entries are consumed | 255 | /// Signalled when ring buffer entries are consumed |
| 255 | std::condition_variable release_cv; | 256 | std::condition_variable_any release_cv; |
| 256 | std::mutex release_mutex; | 257 | std::mutex release_mutex; |
| 257 | }; | 258 | }; |
| 258 | 259 | ||
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 703ddb4a4..ba22595e0 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #ifndef _GNU_SOURCE | 18 | #ifndef _GNU_SOURCE |
| 19 | #define _GNU_SOURCE | 19 | #define _GNU_SOURCE |
| 20 | #endif | 20 | #endif |
| 21 | #include <boost/icl/interval_set.hpp> | ||
| 21 | #include <fcntl.h> | 22 | #include <fcntl.h> |
| 22 | #include <sys/mman.h> | 23 | #include <sys/mman.h> |
| 23 | #include <unistd.h> | 24 | #include <unistd.h> |
| @@ -423,6 +424,7 @@ public: | |||
| 423 | madvise(virtual_base, virtual_size, MADV_HUGEPAGE); | 424 | madvise(virtual_base, virtual_size, MADV_HUGEPAGE); |
| 424 | #endif | 425 | #endif |
| 425 | 426 | ||
| 427 | placeholders.add({0, virtual_size}); | ||
| 426 | good = true; | 428 | good = true; |
| 427 | } | 429 | } |
| 428 | 430 | ||
| @@ -431,6 +433,10 @@ public: | |||
| 431 | } | 433 | } |
| 432 | 434 | ||
| 433 | void Map(size_t virtual_offset, size_t host_offset, size_t length) { | 435 | void Map(size_t virtual_offset, size_t host_offset, size_t length) { |
| 436 | { | ||
| 437 | std::scoped_lock lock{placeholder_mutex}; | ||
| 438 | placeholders.subtract({virtual_offset, virtual_offset + length}); | ||
| 439 | } | ||
| 434 | 440 | ||
| 435 | void* ret = mmap(virtual_base + virtual_offset, length, PROT_READ | PROT_WRITE, | 441 | void* ret = mmap(virtual_base + virtual_offset, length, PROT_READ | PROT_WRITE, |
| 436 | MAP_SHARED | MAP_FIXED, fd, host_offset); | 442 | MAP_SHARED | MAP_FIXED, fd, host_offset); |
| @@ -441,6 +447,19 @@ public: | |||
| 441 | // The method name is wrong. We're still talking about the virtual range. | 447 | // The method name is wrong. We're still talking about the virtual range. |
| 442 | // We don't want to unmap, we want to reserve this memory. | 448 | // We don't want to unmap, we want to reserve this memory. |
| 443 | 449 | ||
| 450 | { | ||
| 451 | std::scoped_lock lock{placeholder_mutex}; | ||
| 452 | auto it = placeholders.find({virtual_offset - 1, virtual_offset + length + 1}); | ||
| 453 | |||
| 454 | if (it != placeholders.end()) { | ||
| 455 | size_t prev_upper = virtual_offset + length; | ||
| 456 | virtual_offset = std::min(virtual_offset, it->lower()); | ||
| 457 | length = std::max(it->upper(), prev_upper) - virtual_offset; | ||
| 458 | } | ||
| 459 | |||
| 460 | placeholders.add({virtual_offset, virtual_offset + length}); | ||
| 461 | } | ||
| 462 | |||
| 444 | void* ret = mmap(virtual_base + virtual_offset, length, PROT_NONE, | 463 | void* ret = mmap(virtual_base + virtual_offset, length, PROT_NONE, |
| 445 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); | 464 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); |
| 446 | ASSERT_MSG(ret != MAP_FAILED, "mmap failed: {}", strerror(errno)); | 465 | ASSERT_MSG(ret != MAP_FAILED, "mmap failed: {}", strerror(errno)); |
| @@ -484,6 +503,9 @@ private: | |||
| 484 | } | 503 | } |
| 485 | 504 | ||
| 486 | int fd{-1}; // memfd file descriptor, -1 is the error value of memfd_create | 505 | int fd{-1}; // memfd file descriptor, -1 is the error value of memfd_create |
| 506 | |||
| 507 | boost::icl::interval_set<size_t> placeholders; ///< Mapped placeholders | ||
| 508 | std::mutex placeholder_mutex; ///< Mutex for placeholders | ||
| 487 | }; | 509 | }; |
| 488 | 510 | ||
| 489 | #else // ^^^ Linux ^^^ vvv Generic vvv | 511 | #else // ^^^ Linux ^^^ vvv Generic vvv |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 157858c82..99602699a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -106,6 +106,8 @@ add_library(core STATIC | |||
| 106 | file_sys/system_archive/time_zone_binary.h | 106 | file_sys/system_archive/time_zone_binary.h |
| 107 | file_sys/vfs.cpp | 107 | file_sys/vfs.cpp |
| 108 | file_sys/vfs.h | 108 | file_sys/vfs.h |
| 109 | file_sys/vfs_cached.cpp | ||
| 110 | file_sys/vfs_cached.h | ||
| 109 | file_sys/vfs_concat.cpp | 111 | file_sys/vfs_concat.cpp |
| 110 | file_sys/vfs_concat.h | 112 | file_sys/vfs_concat.h |
| 111 | file_sys/vfs_layered.cpp | 113 | file_sys/vfs_layered.cpp |
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 4c80e13a9..f786f2add 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include "core/file_sys/patch_manager.h" | 21 | #include "core/file_sys/patch_manager.h" |
| 22 | #include "core/file_sys/registered_cache.h" | 22 | #include "core/file_sys/registered_cache.h" |
| 23 | #include "core/file_sys/romfs.h" | 23 | #include "core/file_sys/romfs.h" |
| 24 | #include "core/file_sys/vfs_cached.h" | ||
| 24 | #include "core/file_sys/vfs_layered.h" | 25 | #include "core/file_sys/vfs_layered.h" |
| 25 | #include "core/file_sys/vfs_vector.h" | 26 | #include "core/file_sys/vfs_vector.h" |
| 26 | #include "core/hle/service/filesystem/filesystem.h" | 27 | #include "core/hle/service/filesystem/filesystem.h" |
| @@ -380,11 +381,11 @@ static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType t | |||
| 380 | 381 | ||
| 381 | auto romfs_dir = FindSubdirectoryCaseless(subdir, "romfs"); | 382 | auto romfs_dir = FindSubdirectoryCaseless(subdir, "romfs"); |
| 382 | if (romfs_dir != nullptr) | 383 | if (romfs_dir != nullptr) |
| 383 | layers.push_back(std::move(romfs_dir)); | 384 | layers.push_back(std::make_shared<CachedVfsDirectory>(romfs_dir)); |
| 384 | 385 | ||
| 385 | auto ext_dir = FindSubdirectoryCaseless(subdir, "romfs_ext"); | 386 | auto ext_dir = FindSubdirectoryCaseless(subdir, "romfs_ext"); |
| 386 | if (ext_dir != nullptr) | 387 | if (ext_dir != nullptr) |
| 387 | layers_ext.push_back(std::move(ext_dir)); | 388 | layers_ext.push_back(std::make_shared<CachedVfsDirectory>(ext_dir)); |
| 388 | } | 389 | } |
| 389 | 390 | ||
| 390 | // When there are no layers to apply, return early as there is no need to rebuild the RomFS | 391 | // When there are no layers to apply, return early as there is no need to rebuild the RomFS |
diff --git a/src/core/file_sys/romfs.cpp b/src/core/file_sys/romfs.cpp index fb5683a6b..614da2130 100644 --- a/src/core/file_sys/romfs.cpp +++ b/src/core/file_sys/romfs.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "core/file_sys/fsmitm_romfsbuild.h" | 9 | #include "core/file_sys/fsmitm_romfsbuild.h" |
| 10 | #include "core/file_sys/romfs.h" | 10 | #include "core/file_sys/romfs.h" |
| 11 | #include "core/file_sys/vfs.h" | 11 | #include "core/file_sys/vfs.h" |
| 12 | #include "core/file_sys/vfs_cached.h" | ||
| 12 | #include "core/file_sys/vfs_concat.h" | 13 | #include "core/file_sys/vfs_concat.h" |
| 13 | #include "core/file_sys/vfs_offset.h" | 14 | #include "core/file_sys/vfs_offset.h" |
| 14 | #include "core/file_sys/vfs_vector.h" | 15 | #include "core/file_sys/vfs_vector.h" |
| @@ -132,7 +133,7 @@ VirtualDir ExtractRomFS(VirtualFile file, RomFSExtractionType type) { | |||
| 132 | out = out->GetSubdirectories().front(); | 133 | out = out->GetSubdirectories().front(); |
| 133 | } | 134 | } |
| 134 | 135 | ||
| 135 | return out; | 136 | return std::make_shared<CachedVfsDirectory>(out); |
| 136 | } | 137 | } |
| 137 | 138 | ||
| 138 | VirtualFile CreateRomFS(VirtualDir dir, VirtualDir ext) { | 139 | VirtualFile CreateRomFS(VirtualDir dir, VirtualDir ext) { |
diff --git a/src/core/file_sys/vfs_cached.cpp b/src/core/file_sys/vfs_cached.cpp new file mode 100644 index 000000000..c3154ee81 --- /dev/null +++ b/src/core/file_sys/vfs_cached.cpp | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/file_sys/vfs_cached.h" | ||
| 5 | #include "core/file_sys/vfs_types.h" | ||
| 6 | |||
| 7 | namespace FileSys { | ||
| 8 | |||
| 9 | CachedVfsDirectory::CachedVfsDirectory(VirtualDir& source_dir) | ||
| 10 | : name(source_dir->GetName()), parent(source_dir->GetParentDirectory()) { | ||
| 11 | for (auto& dir : source_dir->GetSubdirectories()) { | ||
| 12 | dirs.emplace(dir->GetName(), std::make_shared<CachedVfsDirectory>(dir)); | ||
| 13 | } | ||
| 14 | for (auto& file : source_dir->GetFiles()) { | ||
| 15 | files.emplace(file->GetName(), file); | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | CachedVfsDirectory::~CachedVfsDirectory() = default; | ||
| 20 | |||
| 21 | VirtualFile CachedVfsDirectory::GetFile(std::string_view file_name) const { | ||
| 22 | auto it = files.find(file_name); | ||
| 23 | if (it != files.end()) { | ||
| 24 | return it->second; | ||
| 25 | } | ||
| 26 | |||
| 27 | return nullptr; | ||
| 28 | } | ||
| 29 | |||
| 30 | VirtualDir CachedVfsDirectory::GetSubdirectory(std::string_view dir_name) const { | ||
| 31 | auto it = dirs.find(dir_name); | ||
| 32 | if (it != dirs.end()) { | ||
| 33 | return it->second; | ||
| 34 | } | ||
| 35 | |||
| 36 | return nullptr; | ||
| 37 | } | ||
| 38 | |||
| 39 | std::vector<VirtualFile> CachedVfsDirectory::GetFiles() const { | ||
| 40 | std::vector<VirtualFile> out; | ||
| 41 | for (auto& [file_name, file] : files) { | ||
| 42 | out.push_back(file); | ||
| 43 | } | ||
| 44 | return out; | ||
| 45 | } | ||
| 46 | |||
| 47 | std::vector<VirtualDir> CachedVfsDirectory::GetSubdirectories() const { | ||
| 48 | std::vector<VirtualDir> out; | ||
| 49 | for (auto& [dir_name, dir] : dirs) { | ||
| 50 | out.push_back(dir); | ||
| 51 | } | ||
| 52 | return out; | ||
| 53 | } | ||
| 54 | |||
| 55 | std::string CachedVfsDirectory::GetName() const { | ||
| 56 | return name; | ||
| 57 | } | ||
| 58 | |||
| 59 | VirtualDir CachedVfsDirectory::GetParentDirectory() const { | ||
| 60 | return parent; | ||
| 61 | } | ||
| 62 | |||
| 63 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/vfs_cached.h b/src/core/file_sys/vfs_cached.h new file mode 100644 index 000000000..113acac12 --- /dev/null +++ b/src/core/file_sys/vfs_cached.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <string_view> | ||
| 7 | #include <vector> | ||
| 8 | #include "core/file_sys/vfs.h" | ||
| 9 | |||
| 10 | namespace FileSys { | ||
| 11 | |||
| 12 | class CachedVfsDirectory : public ReadOnlyVfsDirectory { | ||
| 13 | public: | ||
| 14 | CachedVfsDirectory(VirtualDir& source_directory); | ||
| 15 | |||
| 16 | ~CachedVfsDirectory() override; | ||
| 17 | VirtualFile GetFile(std::string_view file_name) const override; | ||
| 18 | VirtualDir GetSubdirectory(std::string_view dir_name) const override; | ||
| 19 | std::vector<VirtualFile> GetFiles() const override; | ||
| 20 | std::vector<VirtualDir> GetSubdirectories() const override; | ||
| 21 | std::string GetName() const override; | ||
| 22 | VirtualDir GetParentDirectory() const override; | ||
| 23 | |||
| 24 | private: | ||
| 25 | std::string name; | ||
| 26 | VirtualDir parent; | ||
| 27 | std::map<std::string, VirtualDir, std::less<>> dirs; | ||
| 28 | std::map<std::string, VirtualFile, std::less<>> files; | ||
| 29 | }; | ||
| 30 | |||
| 31 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/vfs_vector.cpp b/src/core/file_sys/vfs_vector.cpp index af1df4c51..251d9d7c9 100644 --- a/src/core/file_sys/vfs_vector.cpp +++ b/src/core/file_sys/vfs_vector.cpp | |||
| @@ -67,23 +67,6 @@ VectorVfsDirectory::VectorVfsDirectory(std::vector<VirtualFile> files_, | |||
| 67 | 67 | ||
| 68 | VectorVfsDirectory::~VectorVfsDirectory() = default; | 68 | VectorVfsDirectory::~VectorVfsDirectory() = default; |
| 69 | 69 | ||
| 70 | VirtualFile VectorVfsDirectory::GetFile(std::string_view file_name) const { | ||
| 71 | if (!optimized_file_index_built) { | ||
| 72 | optimized_file_index.clear(); | ||
| 73 | for (size_t i = 0; i < files.size(); i++) { | ||
| 74 | optimized_file_index.emplace(files[i]->GetName(), i); | ||
| 75 | } | ||
| 76 | optimized_file_index_built = true; | ||
| 77 | } | ||
| 78 | |||
| 79 | const auto it = optimized_file_index.find(file_name); | ||
| 80 | if (it != optimized_file_index.end()) { | ||
| 81 | return files[it->second]; | ||
| 82 | } | ||
| 83 | |||
| 84 | return nullptr; | ||
| 85 | } | ||
| 86 | |||
| 87 | std::vector<VirtualFile> VectorVfsDirectory::GetFiles() const { | 70 | std::vector<VirtualFile> VectorVfsDirectory::GetFiles() const { |
| 88 | return files; | 71 | return files; |
| 89 | } | 72 | } |
| @@ -124,7 +107,6 @@ bool VectorVfsDirectory::DeleteSubdirectory(std::string_view subdir_name) { | |||
| 124 | } | 107 | } |
| 125 | 108 | ||
| 126 | bool VectorVfsDirectory::DeleteFile(std::string_view file_name) { | 109 | bool VectorVfsDirectory::DeleteFile(std::string_view file_name) { |
| 127 | optimized_file_index_built = false; | ||
| 128 | return FindAndRemoveVectorElement(files, file_name); | 110 | return FindAndRemoveVectorElement(files, file_name); |
| 129 | } | 111 | } |
| 130 | 112 | ||
| @@ -142,7 +124,6 @@ VirtualFile VectorVfsDirectory::CreateFile(std::string_view file_name) { | |||
| 142 | } | 124 | } |
| 143 | 125 | ||
| 144 | void VectorVfsDirectory::AddFile(VirtualFile file) { | 126 | void VectorVfsDirectory::AddFile(VirtualFile file) { |
| 145 | optimized_file_index_built = false; | ||
| 146 | files.push_back(std::move(file)); | 127 | files.push_back(std::move(file)); |
| 147 | } | 128 | } |
| 148 | 129 | ||
diff --git a/src/core/file_sys/vfs_vector.h b/src/core/file_sys/vfs_vector.h index c9955755b..bfedb6e42 100644 --- a/src/core/file_sys/vfs_vector.h +++ b/src/core/file_sys/vfs_vector.h | |||
| @@ -105,7 +105,6 @@ public: | |||
| 105 | VirtualDir parent = nullptr); | 105 | VirtualDir parent = nullptr); |
| 106 | ~VectorVfsDirectory() override; | 106 | ~VectorVfsDirectory() override; |
| 107 | 107 | ||
| 108 | VirtualFile GetFile(std::string_view file_name) const override; | ||
| 109 | std::vector<VirtualFile> GetFiles() const override; | 108 | std::vector<VirtualFile> GetFiles() const override; |
| 110 | std::vector<VirtualDir> GetSubdirectories() const override; | 109 | std::vector<VirtualDir> GetSubdirectories() const override; |
| 111 | bool IsWritable() const override; | 110 | bool IsWritable() const override; |
| @@ -127,9 +126,6 @@ private: | |||
| 127 | 126 | ||
| 128 | VirtualDir parent; | 127 | VirtualDir parent; |
| 129 | std::string name; | 128 | std::string name; |
| 130 | |||
| 131 | mutable std::map<std::string, size_t, std::less<>> optimized_file_index; | ||
| 132 | mutable bool optimized_file_index_built{}; | ||
| 133 | }; | 129 | }; |
| 134 | 130 | ||
| 135 | } // namespace FileSys | 131 | } // namespace FileSys |
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index f73a864c3..427dbc8b3 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -968,16 +968,20 @@ void FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(HLERequ | |||
| 968 | void FSP_SRV::OpenDataStorageByCurrentProcess(HLERequestContext& ctx) { | 968 | void FSP_SRV::OpenDataStorageByCurrentProcess(HLERequestContext& ctx) { |
| 969 | LOG_DEBUG(Service_FS, "called"); | 969 | LOG_DEBUG(Service_FS, "called"); |
| 970 | 970 | ||
| 971 | auto current_romfs = fsc.OpenRomFSCurrentProcess(); | 971 | if (!romfs) { |
| 972 | if (current_romfs.Failed()) { | 972 | auto current_romfs = fsc.OpenRomFSCurrentProcess(); |
| 973 | // TODO (bunnei): Find the right error code to use here | 973 | if (current_romfs.Failed()) { |
| 974 | LOG_CRITICAL(Service_FS, "no file system interface available!"); | 974 | // TODO (bunnei): Find the right error code to use here |
| 975 | IPC::ResponseBuilder rb{ctx, 2}; | 975 | LOG_CRITICAL(Service_FS, "no file system interface available!"); |
| 976 | rb.Push(ResultUnknown); | 976 | IPC::ResponseBuilder rb{ctx, 2}; |
| 977 | return; | 977 | rb.Push(ResultUnknown); |
| 978 | return; | ||
| 979 | } | ||
| 980 | |||
| 981 | romfs = current_romfs.Unwrap(); | ||
| 978 | } | 982 | } |
| 979 | 983 | ||
| 980 | auto storage = std::make_shared<IStorage>(system, std::move(current_romfs.Unwrap())); | 984 | auto storage = std::make_shared<IStorage>(system, romfs); |
| 981 | 985 | ||
| 982 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 986 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 983 | rb.Push(ResultSuccess); | 987 | rb.Push(ResultSuccess); |