2020-01-26 10:07:22 -08:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2020-02-24 18:04:12 -08:00
|
|
|
#include <functional>
|
2020-01-26 10:07:22 -08:00
|
|
|
#include <memory>
|
2020-02-24 18:04:12 -08:00
|
|
|
#include <thread>
|
2020-02-11 15:56:24 -08:00
|
|
|
#include "core/hardware_properties.h"
|
2020-01-26 10:07:22 -08:00
|
|
|
|
2020-02-24 18:04:12 -08:00
|
|
|
namespace Common {
|
|
|
|
class Event;
|
|
|
|
class Fiber;
|
|
|
|
} // namespace Common
|
|
|
|
|
2020-01-26 10:07:22 -08:00
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
class System;
|
|
|
|
|
|
|
|
class CpuManager {
|
|
|
|
public:
|
|
|
|
explicit CpuManager(System& system);
|
|
|
|
CpuManager(const CpuManager&) = delete;
|
|
|
|
CpuManager(CpuManager&&) = delete;
|
|
|
|
|
|
|
|
~CpuManager();
|
|
|
|
|
|
|
|
CpuManager& operator=(const CpuManager&) = delete;
|
|
|
|
CpuManager& operator=(CpuManager&&) = delete;
|
|
|
|
|
|
|
|
void Initialize();
|
|
|
|
void Shutdown();
|
|
|
|
|
2020-02-24 18:04:12 -08:00
|
|
|
void Pause(bool paused);
|
|
|
|
|
|
|
|
std::function<void(void*)> GetGuestThreadStartFunc();
|
|
|
|
std::function<void(void*)> GetIdleThreadStartFunc();
|
|
|
|
std::function<void(void*)> GetSuspendThreadStartFunc();
|
|
|
|
void* GetStartFuncParamater();
|
2020-01-26 10:07:22 -08:00
|
|
|
|
2020-02-24 18:04:12 -08:00
|
|
|
private:
|
|
|
|
static void GuestThreadFunction(void* cpu_manager);
|
|
|
|
static void IdleThreadFunction(void* cpu_manager);
|
|
|
|
static void SuspendThreadFunction(void* cpu_manager);
|
2020-01-26 10:07:22 -08:00
|
|
|
|
2020-02-24 18:04:12 -08:00
|
|
|
void RunGuestThread();
|
|
|
|
void RunIdleThread();
|
|
|
|
void RunSuspendThread();
|
2020-01-26 10:07:22 -08:00
|
|
|
|
2020-02-24 18:04:12 -08:00
|
|
|
static void ThreadStart(CpuManager& cpu_manager, std::size_t core);
|
2020-01-26 10:07:22 -08:00
|
|
|
|
2020-02-24 18:04:12 -08:00
|
|
|
void RunThread(std::size_t core);
|
|
|
|
|
|
|
|
struct CoreData {
|
|
|
|
std::shared_ptr<Common::Fiber> host_context;
|
|
|
|
std::unique_ptr<Common::Event> enter_barrier;
|
|
|
|
std::unique_ptr<Common::Event> exit_barrier;
|
|
|
|
std::atomic<bool> is_running;
|
|
|
|
std::atomic<bool> is_paused;
|
|
|
|
std::atomic<bool> initialized;
|
|
|
|
std::unique_ptr<std::thread> host_thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::atomic<bool> running_mode{};
|
|
|
|
std::atomic<bool> paused_state{};
|
|
|
|
|
|
|
|
std::array<CoreData, Core::Hardware::NUM_CPU_CORES> core_data{};
|
2020-01-26 10:07:22 -08:00
|
|
|
|
|
|
|
System& system;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Core
|