RTScheduler.hh 855 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef RTSCHEDULER_HH
  2. #define RTSCHEDULER_HH
  3. #include "SchedulerQueue.hh"
  4. #include "Timer.hh"
  5. #include "likely.hh"
  6. #include <cstdint>
  7. namespace openmsx {
  8. class RTSchedulable;
  9. struct RTSyncPoint
  10. {
  11. uint64_t time;
  12. RTSchedulable* schedulable;
  13. };
  14. class RTScheduler
  15. {
  16. public:
  17. /** Execute all expired RTSchedulables. */
  18. inline void execute()
  19. {
  20. auto limit = Timer::getTime();
  21. if (!queue.empty() && unlikely(limit >= queue.front().time)) {
  22. scheduleHelper(limit); // slow path not inlined
  23. }
  24. }
  25. private:
  26. // These are called by RTSchedulable
  27. friend class RTSchedulable;
  28. void add(uint64_t delta, RTSchedulable& schedulable);
  29. bool remove(RTSchedulable& schedulable);
  30. bool isPending(const RTSchedulable& schedulable) const;
  31. private:
  32. void scheduleHelper(uint64_t limit);
  33. SchedulerQueue<RTSyncPoint> queue;
  34. };
  35. } // namespace openmsx
  36. #endif