kernel/physical_core: Make use of std::unique_ptr

shared_ptr was used in 2d1984c20c due to a
misunderstanding of how the language generates move constructors and
move assignment operators.

If a destructor is user-provided, then the compiler won't generate the
move constructor and move assignment operators by default--they must be
explicitly opted into.

The reason for the compilation errors is due to the fact that the
language will fall back to attempting to use the copy constructor/copy
assignment operators if the respective move constructor or move
assignment operator is unavailable.

Given that we explicitly opt into them now, the the move constructor and
move assignment operators will be generated as expected.
This commit is contained in:
Lioncash 2020-01-30 18:38:28 -05:00
parent 16e7b7b83d
commit 2de2bb980e
2 changed files with 10 additions and 4 deletions

View file

@ -20,13 +20,13 @@ PhysicalCore::PhysicalCore(Core::System& system, std::size_t id,
Core::ExclusiveMonitor& exclusive_monitor)
: core_index{id} {
#ifdef ARCHITECTURE_x86_64
arm_interface = std::make_shared<Core::ARM_Dynarmic>(system, exclusive_monitor, core_index);
arm_interface = std::make_unique<Core::ARM_Dynarmic>(system, exclusive_monitor, core_index);
#else
arm_interface = std::make_shared<Core::ARM_Unicorn>(system);
LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
#endif
scheduler = std::make_shared<Kernel::Scheduler>(system, *arm_interface, core_index);
scheduler = std::make_unique<Kernel::Scheduler>(system, *arm_interface, core_index);
}
PhysicalCore::~PhysicalCore() = default;

View file

@ -24,6 +24,12 @@ public:
PhysicalCore(Core::System& system, std::size_t id, Core::ExclusiveMonitor& exclusive_monitor);
~PhysicalCore();
PhysicalCore(const PhysicalCore&) = delete;
PhysicalCore& operator=(const PhysicalCore&) = delete;
PhysicalCore(PhysicalCore&&) = default;
PhysicalCore& operator=(PhysicalCore&&) = default;
/// Execute current jit state
void Run();
/// Execute a single instruction in current jit.
@ -64,8 +70,8 @@ public:
private:
std::size_t core_index;
std::shared_ptr<Core::ARM_Interface> arm_interface;
std::shared_ptr<Kernel::Scheduler> scheduler;
std::unique_ptr<Core::ARM_Interface> arm_interface;
std::unique_ptr<Kernel::Scheduler> scheduler;
};
} // namespace Kernel