openMSX
Schedulable.hh
Go to the documentation of this file.
1#ifndef SCHEDULABLE_HH
2#define SCHEDULABLE_HH
3
4#include "EmuTime.hh"
5#include "serialize.hh"
6#include "serialize_meta.hh"
7#include "serialize_stl.hh"
8#include <cassert>
9#include <vector>
10
11namespace openmsx {
12
13class Scheduler;
14
15// For backwards-compatible savestates
17{
18 template<typename Archive>
19 void serialize(Archive& ar, unsigned /*version*/) {
20 assert(Archive::IS_LOADER);
21 ar.serialize("time", time,
22 "type", userData);
23 }
24
25 EmuTime time = EmuTime::zero();
26 int userData = 0;
27};
28
34{
35public:
36 Schedulable(const Schedulable&) = delete;
40
45 virtual void executeUntil(EmuTime::param time) = 0;
46
58 virtual void schedulerDeleted();
59
60 [[nodiscard]] Scheduler& getScheduler() const { return scheduler; }
61
64 [[nodiscard]] EmuTime::param getCurrentTime() const;
65
66 template<typename Archive>
67 void serialize(Archive& ar, unsigned version);
68
69 template<typename Archive>
70 static std::vector<SyncPointBW> serializeBW(Archive& ar) {
71 assert(Archive::IS_LOADER);
72 ar.beginTag("Schedulable");
73 std::vector<SyncPointBW> result;
74 ar.serialize("syncPoints", result);
75 ar.endTag("Schedulable");
76 return result;
77 }
78 template<typename Archive>
79 static void restoreOld(Archive& ar, std::vector<Schedulable*> schedulables) {
80 assert(Archive::IS_LOADER);
81 for (auto* s : schedulables) {
82 s->removeSyncPoints();
83 }
84 for (auto& old : serializeBW(ar)) {
85 unsigned i = old.userData;
86 if (i < schedulables.size()) {
87 schedulables[i]->setSyncPoint(old.time);
88 }
89 }
90 }
91
92protected:
93 explicit Schedulable(Scheduler& scheduler);
95
96 void setSyncPoint(EmuTime::param timestamp);
97 bool removeSyncPoint();
98 void removeSyncPoints();
99 [[nodiscard]] bool pendingSyncPoint() const;
100 [[nodiscard]] bool pendingSyncPoint(EmuTime& result) const;
101
102private:
103 Scheduler& scheduler;
104};
106
107} // namespace openmsx
108
109#endif
Every class that wants to get scheduled at some point must inherit from this class.
Schedulable & operator=(Schedulable &&)=delete
virtual void executeUntil(EmuTime::param time)=0
When the previously registered syncPoint is reached, this method gets called.
void setSyncPoint(EmuTime::param timestamp)
void serialize(Archive &ar, unsigned version)
Schedulable(const Schedulable &)=delete
Schedulable & operator=(const Schedulable &)=delete
virtual void schedulerDeleted()
Just before the the Scheduler is deleted, it calls this method of all the Schedulables that are still...
bool pendingSyncPoint() const
Scheduler & getScheduler() const
static void restoreOld(Archive &ar, std::vector< Schedulable * > schedulables)
EmuTime::param getCurrentTime() const
Convenience method: This is the same as getScheduler().getCurrentTime().
Schedulable(Schedulable &&)=delete
static std::vector< SyncPointBW > serializeBW(Archive &ar)
This file implemented 3 utility functions:
Definition Autofire.cc:11
#define REGISTER_BASE_CLASS(CLASS, NAME)
void serialize(Archive &ar, unsigned)