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 if (EmuTime next = getNext(); limit >= next) [[unlikely]] {
64 scheduleHelper(limit, next); // slow path not inlined
65 }
66 scheduleTime = limit;
67 }
68
69 template<typename Archive>
70 void serialize(Archive& ar, unsigned version);
71
72private: // -> intended for Schedulable
73 friend class Schedulable;
74
84 void setSyncPoint(EmuTime::param timestamp, Schedulable& device);
85
86 [[nodiscard]] SyncPoints getSyncPoints(const Schedulable& device) const;
87
95 bool removeSyncPoint(const Schedulable& device);
96
99 void removeSyncPoints(const Schedulable& device);
100
104 [[nodiscard]] bool pendingSyncPoint(const Schedulable& device, EmuTime& result) const;
105
106private:
107 void scheduleHelper(EmuTime::param limit, EmuTime next);
108
109private:
114 EmuTime scheduleTime = EmuTime::zero();
115 MSXCPU* cpu = nullptr;
116 bool scheduleInProgress = false;
117};
118
119} // namespace openmsx
120
121#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:82
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:124
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:113
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:11