summaryrefslogtreecommitdiffstats
path: root/src/core/core_manager.h
blob: 7bc9679c16962b394fa03a04116b0f9e9091dbb9 (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
60
61
62
63
64
65
// Copyright 2018 yuzu emulator team
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <atomic>
#include <condition_variable>
#include <cstddef>
#include <memory>
#include <mutex>
#include "common/common_types.h"

namespace Kernel {
class GlobalScheduler;
class PhysicalCore;
} // namespace Kernel

namespace Core {
class System;
}

namespace Core::Timing {
class CoreTiming;
}

namespace Memory {
class Memory;
}

namespace Core {

constexpr unsigned NUM_CPU_CORES{4};

class CoreManager {
public:
    CoreManager(System& system, std::size_t core_index);
    ~CoreManager();

    void RunLoop(bool tight_loop = true);

    void SingleStep();

    void PrepareReschedule();

    bool IsMainCore() const {
        return core_index == 0;
    }

    std::size_t CoreIndex() const {
        return core_index;
    }

private:
    void Reschedule();

    Kernel::GlobalScheduler& global_scheduler;
    Kernel::PhysicalCore& physical_core;
    Timing::CoreTiming& core_timing;

    std::atomic<bool> reschedule_pending = false;
    std::size_t core_index;
};

} // namespace Core