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;
38
43 virtual void executeUntil(EmuTime::param time) = 0;
44
56 virtual void schedulerDeleted();
57
58 [[nodiscard]] Scheduler& getScheduler() const { return scheduler; }
59
62 [[nodiscard]] EmuTime::param getCurrentTime() const;
63
64 template<typename Archive>
65 void serialize(Archive& ar, unsigned version);
66
67 template<typename Archive>
68 static std::vector<SyncPointBW> serializeBW(Archive& ar) {
69 assert(Archive::IS_LOADER);
70 ar.beginTag("Schedulable");
71 std::vector<SyncPointBW> result;
72 ar.serialize("syncPoints", result);
73 ar.endTag("Schedulable");
74 return result;
75 }
76 template<typename Archive>
77 static void restoreOld(Archive& ar, std::vector<Schedulable*> schedulables) {
78 assert(Archive::IS_LOADER);
79 for (auto* s : schedulables) {
80 s->removeSyncPoints();
81 }
82 for (auto& old : serializeBW(ar)) {
83 unsigned i = old.userData;
84 if (i < schedulables.size()) {
85 schedulables[i]->setSyncPoint(old.time);
86 }
87 }
88 }
89
90protected:
91 explicit Schedulable(Scheduler& scheduler);
93
94 void setSyncPoint(EmuTime::param timestamp);
95 bool removeSyncPoint();
96 void removeSyncPoints();
97 [[nodiscard]] bool pendingSyncPoint() const;
98 [[nodiscard]] bool pendingSyncPoint(EmuTime& result) const;
99
100private:
101 Scheduler& scheduler;
102};
104
105} // namespace openmsx
106
107#endif
Every class that wants to get scheduled at some point must inherit from this class.
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().
static std::vector< SyncPointBW > serializeBW(Archive &ar)
This file implemented 3 utility functions:
Definition Autofire.cc:9
#define REGISTER_BASE_CLASS(CLASS, NAME)
void serialize(Archive &ar, unsigned)