openMSX
Schedulable.cc
Go to the documentation of this file.
1 #include "Schedulable.hh"
2 #include "Scheduler.hh"
3 #include <iostream>
4 
5 namespace openmsx {
6 
8  : scheduler(scheduler_)
9 {
10 }
11 
13 {
15 }
16 
18 {
19  std::cerr << "Internal error: Schedulable \"" << typeid(*this).name()
20  << "\" failed to unregister.\n";
21 }
22 
23 void Schedulable::setSyncPoint(EmuTime::param timestamp)
24 {
25  scheduler.setSyncPoint(timestamp, *this);
26 }
27 
29 {
30  return scheduler.removeSyncPoint(*this);
31 }
32 
34 {
35  scheduler.removeSyncPoints(*this);
36 }
37 
39 {
40  auto dummy = EmuTime::dummy();
41  return scheduler.pendingSyncPoint(*this, dummy);
42 }
43 
44 bool Schedulable::pendingSyncPoint(EmuTime& result) const
45 {
46  return scheduler.pendingSyncPoint(*this, result);
47 }
48 
49 EmuTime::param Schedulable::getCurrentTime() const
50 {
51  return scheduler.getCurrentTime();
52 }
53 
54 template <typename Archive>
55 void Schedulable::serialize(Archive& ar, unsigned /*version*/)
56 {
57  Scheduler::SyncPoints syncPoints;
58  if (!ar.isLoader()) {
59  syncPoints = scheduler.getSyncPoints(*this);
60  }
61  ar.serialize("syncPoints", syncPoints);
62  if (ar.isLoader()) {
64  for (auto& s : syncPoints) {
65  setSyncPoint(s.getTime());
66  }
67  }
68 }
70 
71 } // namespace openmsx
bool pendingSyncPoint() const
Definition: Schedulable.cc:38
EmuTime::param getCurrentTime() const
Convenience method: This is the same as getScheduler().getCurrentTime().
Definition: Schedulable.cc:49
virtual void schedulerDeleted()
Just before the the Scheduler is deleted, it calls this method of all the Schedulables that are still...
Definition: Schedulable.cc:17
void serialize(Archive &ar, unsigned version)
Definition: Schedulable.cc:55
EmuTime::param getCurrentTime() const
Get the current scheduler time.
Definition: Scheduler.cc:85
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:33
std::vector< SynchronizationPoint > SyncPoints
Definition: Scheduler.hh:36
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
Schedulable(const Schedulable &)=delete
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
void setSyncPoint(EmuTime::param timestamp)
Definition: Schedulable.cc:23