Schedulable.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "Schedulable.hh"
  2. #include "Scheduler.hh"
  3. #include <iostream>
  4. namespace openmsx {
  5. Schedulable::Schedulable(Scheduler& scheduler_)
  6. : scheduler(scheduler_)
  7. {
  8. }
  9. Schedulable::~Schedulable()
  10. {
  11. removeSyncPoints();
  12. }
  13. void Schedulable::schedulerDeleted()
  14. {
  15. std::cerr << "Internal error: Schedulable \"" << typeid(*this).name()
  16. << "\" failed to unregister.\n";
  17. }
  18. void Schedulable::setSyncPoint(EmuTime::param timestamp)
  19. {
  20. scheduler.setSyncPoint(timestamp, *this);
  21. }
  22. bool Schedulable::removeSyncPoint()
  23. {
  24. return scheduler.removeSyncPoint(*this);
  25. }
  26. void Schedulable::removeSyncPoints()
  27. {
  28. scheduler.removeSyncPoints(*this);
  29. }
  30. bool Schedulable::pendingSyncPoint() const
  31. {
  32. auto dummy = EmuTime::dummy();
  33. return scheduler.pendingSyncPoint(*this, dummy);
  34. }
  35. bool Schedulable::pendingSyncPoint(EmuTime& result) const
  36. {
  37. return scheduler.pendingSyncPoint(*this, result);
  38. }
  39. EmuTime::param Schedulable::getCurrentTime() const
  40. {
  41. return scheduler.getCurrentTime();
  42. }
  43. template <typename Archive>
  44. void Schedulable::serialize(Archive& ar, unsigned /*version*/)
  45. {
  46. Scheduler::SyncPoints syncPoints;
  47. if (!ar.isLoader()) {
  48. syncPoints = scheduler.getSyncPoints(*this);
  49. }
  50. ar.serialize("syncPoints", syncPoints);
  51. if (ar.isLoader()) {
  52. removeSyncPoints();
  53. for (auto& s : syncPoints) {
  54. setSyncPoint(s.getTime());
  55. }
  56. }
  57. }
  58. INSTANTIATE_SERIALIZE_METHODS(Schedulable);
  59. } // namespace openmsx