2018-05-02 04:21:38 +02:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-05-03 03:26:14 +02:00
|
|
|
#include <condition_variable>
|
2018-05-02 04:21:38 +02:00
|
|
|
#include <memory>
|
2018-05-03 03:26:14 +02:00
|
|
|
#include <mutex>
|
2018-05-02 04:21:38 +02:00
|
|
|
#include <string>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
class ARM_Interface;
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
class Scheduler;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
2018-05-03 03:26:14 +02:00
|
|
|
constexpr unsigned NUM_CPU_CORES{4};
|
|
|
|
|
|
|
|
class CpuBarrier {
|
|
|
|
public:
|
|
|
|
void Rendezvous() {
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
|
|
|
|
--cores_waiting;
|
|
|
|
if (!cores_waiting) {
|
|
|
|
cores_waiting = NUM_CPU_CORES;
|
|
|
|
condition.notify_all();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
condition.wait(lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned cores_waiting{NUM_CPU_CORES};
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable condition;
|
|
|
|
};
|
|
|
|
|
2018-05-02 04:21:38 +02:00
|
|
|
class Cpu {
|
|
|
|
public:
|
2018-05-03 03:26:14 +02:00
|
|
|
Cpu(std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index);
|
2018-05-02 04:21:38 +02:00
|
|
|
|
|
|
|
void RunLoop(bool tight_loop = true);
|
|
|
|
|
|
|
|
void SingleStep();
|
|
|
|
|
|
|
|
void PrepareReschedule();
|
|
|
|
|
|
|
|
ARM_Interface& CPU() {
|
|
|
|
return *arm_interface;
|
|
|
|
}
|
|
|
|
|
|
|
|
Kernel::Scheduler& Scheduler() {
|
|
|
|
return *scheduler;
|
|
|
|
}
|
|
|
|
|
2018-05-03 03:26:14 +02:00
|
|
|
bool IsMainCore() const {
|
|
|
|
return core_index == 0;
|
|
|
|
}
|
|
|
|
|
2018-05-02 04:21:38 +02:00
|
|
|
private:
|
|
|
|
void Reschedule();
|
|
|
|
|
|
|
|
std::shared_ptr<ARM_Interface> arm_interface;
|
2018-05-03 03:26:14 +02:00
|
|
|
std::shared_ptr<CpuBarrier> cpu_barrier;
|
2018-05-02 04:21:38 +02:00
|
|
|
std::unique_ptr<Kernel::Scheduler> scheduler;
|
|
|
|
|
|
|
|
bool reschedule_pending{};
|
2018-05-03 03:26:14 +02:00
|
|
|
size_t core_index;
|
2018-05-02 04:21:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Core
|