OXYGENHUB
◆ main openmsx / src / Schedulable.cc
1.3 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "Schedulable.hh"
2
3
#include "Scheduler.hh"
4
5
#include <iostream>
6
7
namespace openmsx {
8
9
Schedulable::Schedulable(Scheduler& scheduler_)
10
	: scheduler(scheduler_)
11
{
12
}
13
14
Schedulable::~Schedulable()
15
{
16
	removeSyncPoints();
17
}
18
19
void Schedulable::schedulerDeleted()
20
{
21
	std::cerr << "Internal error: Schedulable \"" << typeid(*this).name()
22
	          << "\" failed to unregister.\n";
23
}
24
25
void Schedulable::setSyncPoint(EmuTime timestamp)
26
{
27
	scheduler.setSyncPoint(timestamp, *this);
28
}
29
30
bool Schedulable::removeSyncPoint()
31
{
32
	return scheduler.removeSyncPoint(*this);
33
}
34
35
void Schedulable::removeSyncPoints()
36
{
37
	scheduler.removeSyncPoints(*this);
38
}
39
40
std::optional<EmuTime> Schedulable::isPending() const
41
{
42
	return scheduler.isPending(*this);
43
}
44
45
EmuTime Schedulable::getCurrentTime() const
46
{
47
	return scheduler.getCurrentTime();
48
}
49
50
template<typename Archive>
51
void Schedulable::serialize(Archive& ar, unsigned /*version*/)
52
{
53
	Scheduler::SyncPoints syncPoints;
54
	if constexpr (!Archive::IS_LOADER) {
55
		syncPoints = scheduler.getSyncPoints(*this);
56
	}
57
	ar.serialize("syncPoints", syncPoints);
58
	if constexpr (Archive::IS_LOADER) {
59
		removeSyncPoints();
60
		for (const auto& s : syncPoints) {
61
			setSyncPoint(s.getTime());
62
		}
63
	}
64
}
65
INSTANTIATE_SERIALIZE_METHODS(Schedulable);
66
67
} // namespace openmsx