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
This commit is contained in:
parent
fa46dbdf0b
commit
5b7d21c3cd
|
@ -58,6 +58,7 @@ add_library(core STATIC
|
||||||
file_sys/disk_archive.h
|
file_sys/disk_archive.h
|
||||||
file_sys/errors.h
|
file_sys/errors.h
|
||||||
file_sys/file_backend.h
|
file_sys/file_backend.h
|
||||||
|
file_sys/delay_generator.cpp
|
||||||
file_sys/delay_generator.h
|
file_sys/delay_generator.h
|
||||||
file_sys/ivfc_archive.cpp
|
file_sys/ivfc_archive.cpp
|
||||||
file_sys/ivfc_archive.h
|
file_sys/ivfc_archive.h
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright 2018 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#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<u64>(static_cast<u64>(length) * slope + offset, minimum);
|
||||||
|
return IPCDelayNanoseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace FileSys
|
|
@ -4,10 +4,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include "common/common_types.h"
|
||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
class DelayGenerator {
|
class DelayGenerator {
|
||||||
public:
|
public:
|
||||||
|
virtual ~DelayGenerator();
|
||||||
virtual u64 GetReadDelayNs(std::size_t length) = 0;
|
virtual u64 GetReadDelayNs(std::size_t length) = 0;
|
||||||
|
|
||||||
// TODO (B3N30): Add getter for all other file/directory io operations
|
// TODO (B3N30): Add getter for all other file/directory io operations
|
||||||
|
@ -15,15 +19,7 @@ public:
|
||||||
|
|
||||||
class DefaultDelayGenerator : public DelayGenerator {
|
class DefaultDelayGenerator : public DelayGenerator {
|
||||||
public:
|
public:
|
||||||
u64 GetReadDelayNs(std::size_t length) override {
|
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<u64>(static_cast<u64>(length) * slope + offset, minimum);
|
|
||||||
return IPCDelayNanoseconds;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
|
Reference in New Issue