| 1 |
#ifndef RTSCHEDULER_HH |
| 2 |
#define RTSCHEDULER_HH |
| 3 |
|
| 4 |
#include "SchedulerQueue.hh" |
| 5 |
#include "Timer.hh" |
| 6 |
|
| 7 |
#include <cstdint> |
| 8 |
#include <optional> |
| 9 |
|
| 10 |
namespace openmsx { |
| 11 |
|
| 12 |
class RTSchedulable; |
| 13 |
|
| 14 |
struct RTSyncPoint |
| 15 |
{ |
| 16 |
uint64_t time; |
| 17 |
RTSchedulable* schedulable; |
| 18 |
}; |
| 19 |
|
| 20 |
class RTScheduler |
| 21 |
{ |
| 22 |
public: |
| 23 |
|
| 24 |
void execute() { |
| 25 |
if (!queue.empty()) { |
| 26 |
auto limit = Timer::getTime(); |
| 27 |
if (limit >= queue.front().time) [[unlikely]] { |
| 28 |
scheduleHelper(limit); |
| 29 |
} |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
[[nodiscard]] std::optional<uint64_t> getNextTime() const { |
| 37 |
return queue.empty() ? std::nullopt |
| 38 |
: std::optional(queue.front().time); |
| 39 |
} |
| 40 |
|
| 41 |
private: |
| 42 |
|
| 43 |
friend class RTSchedulable; |
| 44 |
void add(uint64_t delta, RTSchedulable& schedulable); |
| 45 |
bool remove(RTSchedulable& schedulable); |
| 46 |
[[nodiscard]] bool isPending(const RTSchedulable& schedulable) const; |
| 47 |
|
| 48 |
void scheduleHelper(uint64_t limit); |
| 49 |
|
| 50 |
private: |
| 51 |
SchedulerQueue<RTSyncPoint> queue; |
| 52 |
}; |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
#endif |