summaryrefslogtreecommitdiffstats
path: root/src/core/cpu_core_manager.h
blob: a4d70ec56142e9fcb822af903a172d2a5b96c581 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2018 yuzu emulator team
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <array>
#include <map>
#include <memory>
#include <thread>

namespace Core {

class Cpu;
class CpuBarrier;
class ExclusiveMonitor;
class System;

class CpuCoreManager {
public:
    CpuCoreManager();
    CpuCoreManager(const CpuCoreManager&) = delete;
    CpuCoreManager(CpuCoreManager&&) = delete;

    ~CpuCoreManager();

    CpuCoreManager& operator=(const CpuCoreManager&) = delete;
    CpuCoreManager& operator=(CpuCoreManager&&) = delete;

    void Initialize(System& system);
    void Shutdown();

    Cpu& GetCore(std::size_t index);
    const Cpu& GetCore(std::size_t index) const;

    Cpu& GetCurrentCore();
    const Cpu& GetCurrentCore() const;

    ExclusiveMonitor& GetExclusiveMonitor();
    const ExclusiveMonitor& GetExclusiveMonitor() const;

    void RunLoop(bool tight_loop);

    void InvalidateAllInstructionCaches();

private:
    static constexpr std::size_t NUM_CPU_CORES = 4;

    std::unique_ptr<ExclusiveMonitor> exclusive_monitor;
    std::unique_ptr<CpuBarrier> barrier;
    std::array<std::unique_ptr<Cpu>, NUM_CPU_CORES> cores;
    std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> core_threads;
    std::size_t active_core{}; ///< Active core, only used in single thread mode

    /// Map of guest threads to CPU cores
    std::map<std::thread::id, Cpu*> thread_to_cpu;
};

} // namespace Core