From 5b7d21c3cd5dc3e033fb076340f81464d4a8ee1a Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Sat, 27 Oct 2018 00:46:03 -0400 Subject: [PATCH] FileSys/DelayGenerator: add missing #include and virtual dtor (#4363) * FileSys/DelayGenerator: add missing #include and virtual dtor Added the needed include so that it won't cause error if another file includes this without including the depended files Deleting a virtual class via base type without virtual dtor is UB, which happens inFileBackend. * FileSys/DelayGenerator: move function definition into cpp file/n/nTo avoid generating vtable in all units that includes the header file * filesys/delay_generator: rearrange #include --- src/core/CMakeLists.txt | 1 + src/core/file_sys/delay_generator.cpp | 22 ++++++++++++++++++++++ src/core/file_sys/delay_generator.h | 14 +++++--------- 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 src/core/file_sys/delay_generator.cpp diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c30ddcbdd..18833eb0a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -58,6 +58,7 @@ add_library(core STATIC file_sys/disk_archive.h file_sys/errors.h file_sys/file_backend.h + file_sys/delay_generator.cpp file_sys/delay_generator.h file_sys/ivfc_archive.cpp file_sys/ivfc_archive.h diff --git a/src/core/file_sys/delay_generator.cpp b/src/core/file_sys/delay_generator.cpp new file mode 100644 index 000000000..654550061 --- /dev/null +++ b/src/core/file_sys/delay_generator.cpp @@ -0,0 +1,22 @@ +// Copyright 2018 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include "core/file_sys/delay_generator.h" + +namespace FileSys { + +DelayGenerator::~DelayGenerator() = default; + +u64 DefaultDelayGenerator::GetReadDelayNs(std::size_t length) { + // This is the delay measured for a romfs read. + // For now we will take that as a default + static constexpr u64 slope(94); + static constexpr u64 offset(582778); + static constexpr u64 minimum(663124); + u64 IPCDelayNanoseconds = std::max(static_cast(length) * slope + offset, minimum); + return IPCDelayNanoseconds; +} + +} // namespace FileSys diff --git a/src/core/file_sys/delay_generator.h b/src/core/file_sys/delay_generator.h index c43a5c026..06ef97281 100644 --- a/src/core/file_sys/delay_generator.h +++ b/src/core/file_sys/delay_generator.h @@ -4,10 +4,14 @@ #pragma once +#include +#include "common/common_types.h" + namespace FileSys { class DelayGenerator { public: + virtual ~DelayGenerator(); virtual u64 GetReadDelayNs(std::size_t length) = 0; // TODO (B3N30): Add getter for all other file/directory io operations @@ -15,15 +19,7 @@ public: class DefaultDelayGenerator : public DelayGenerator { public: - u64 GetReadDelayNs(std::size_t length) override { - // This is the delay measured for a romfs read. - // For now we will take that as a default - static constexpr u64 slope(94); - static constexpr u64 offset(582778); - static constexpr u64 minimum(663124); - u64 IPCDelayNanoseconds = std::max(static_cast(length) * slope + offset, minimum); - return IPCDelayNanoseconds; - } + u64 GetReadDelayNs(std::size_t length) override; }; } // namespace FileSys