openMSX
Scheduler.hh
Go to the documentation of this file.
1#ifndef SCHEDULER_HH
2#define SCHEDULER_HH
3
4#include "EmuTime.hh"
5#include "SchedulerQueue.hh"
6#include <vector>
7
8namespace openmsx {
9
10class Schedulable;
11class MSXCPU;
12
14{
15public:
17 SynchronizationPoint(EmuTime::param time, Schedulable* dev)
18 : timeStamp(time), device(dev) {}
19 [[nodiscard]] EmuTime::param getTime() const { return timeStamp; }
20 void setTime(EmuTime::param time) { timeStamp = time; }
21 [[nodiscard]] Schedulable* getDevice() const { return device; }
22
23 template<typename Archive>
24 void serialize(Archive& ar, unsigned version);
25
26private:
27 EmuTime timeStamp = EmuTime::zero();
28 Schedulable* device = nullptr;
29};
30
31
33{
34public:
35 using SyncPoints = std::vector<SynchronizationPoint>;
36
37 Scheduler() = default;
38 ~Scheduler();
39
40 void setCPU(MSXCPU* cpu_)
41 {
42 cpu = cpu_;
43 }
44
48 [[nodiscard]] EmuTime::param getCurrentTime() const;
49
53 [[nodiscard]] inline EmuTime::param getNext() const
54 {
55 return queue.front().getTime();
56 }
57
61 inline void schedule(EmuTime::param limit)
62 {
63 EmuTime next = getNext();
64 if (limit >= next) [[unlikely]] {
65 scheduleHelper(limit, next); // slow path not inlined
66 }
67 scheduleTime = limit;
68 }
69
70 template<typename Archive>
71 void serialize(Archive& ar, unsigned version);
72
73private: // -> intended for Schedulable
74 friend class Schedulable;
75
85 void setSyncPoint(EmuTime::param timestamp, Schedulable& device);
86
87 [[nodiscard]] SyncPoints getSyncPoints(const Schedulable& device) const;
88
96 bool removeSyncPoint(Schedulable& device);
97
100 void removeSyncPoints(Schedulable& device);
101
105 [[nodiscard]] bool pendingSyncPoint(const Schedulable& device, EmuTime& result) const;
106
107private:
108 void scheduleHelper(EmuTime::param limit, EmuTime next);
109
110private:
115 EmuTime scheduleTime = EmuTime::zero();
116 MSXCPU* cpu = nullptr;
117 bool scheduleInProgress = false;
118};
119
120} // namespace openmsx
121
122#endif
Every class that wants to get scheduled at some point must inherit from this class.
EmuTime::param getCurrentTime() const
Get the current scheduler time.
Definition Scheduler.cc:84
void schedule(EmuTime::param limit)
Schedule till a certain moment in time.
Definition Scheduler.hh:61
void serialize(Archive &ar, unsigned version)
Definition Scheduler.cc:126
void setCPU(MSXCPU *cpu_)
Definition Scheduler.hh:40
std::vector< SynchronizationPoint > SyncPoints
Definition Scheduler.hh:35
EmuTime::param getNext() const
TODO.
Definition Scheduler.hh:53
void serialize(Archive &ar, unsigned version)
Definition Scheduler.cc:115
SynchronizationPoint(EmuTime::param time, Schedulable *dev)
Definition Scheduler.hh:17
void setTime(EmuTime::param time)
Definition Scheduler.hh:20
EmuTime::param getTime() const
Definition Scheduler.hh:19
Schedulable * getDevice() const
Definition Scheduler.hh:21
This file implemented 3 utility functions:
Definition Autofire.cc:9