23 std::scoped_lock lock(mutex);
24 auto& priorityMap = listeners[size_t(type)];
26 assert(!
contains(priorityMap, &listener, &Entry::listener));
29 priorityMap.emplace(it, Entry{priority, &listener});
35 std::scoped_lock lock(mutex);
36 auto& priorityMap = listeners[size_t(type)];
37 priorityMap.erase(
rfind_unguarded(priorityMap, &listener, &Entry::listener));
48 std::unique_lock lock(mutex);
49 if (!listeners[
size_t(
getType(event))].empty()) {
50 scheduledEvents.push_back(std::move(event));
56 condition.notify_all();
64 return contains(listeners[
size_t(type)], listener, &Entry::listener);
69 static PriorityMap priorityMapCopy;
70 static EventQueue eventsCopy;
78 std::unique_lock lock(mutex);
86 while (!scheduledEvents.empty()) {
87 assert(eventsCopy.empty());
88 swap(eventsCopy, scheduledEvents);
89 for (
const auto& event : eventsCopy) {
91 priorityMapCopy = listeners[size_t(type)];
94 for (
const auto& e : priorityMapCopy) {
97 if (!isRegistered(type, e.listener))
continue;
99 if (e.priority > allowPriority)
break;
102 if (e.listener->signalEvent(event)) {
103 allowPriority = e.priority;
114 std::chrono::microseconds duration(us);
115 std::unique_lock lock(cvMutex);
116 return condition.wait_for(lock, duration) == std::cv_status::timeout;
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
void distributeEvent(Event &&event)
Schedule the given event for delivery.
EventDistributor(Reactor &reactor)
bool sleep(unsigned us)
Sleep for the specified amount of time, but return early when (another thread) called the distributeE...
void deliverEvents()
This actually delivers the events.
void registerEventListener(EventType type, EventListener &listener, Priority priority=Priority::OTHER)
Registers a given object to receive certain events.
Priority
Priorities from high to low, higher priority listeners can block events for lower priority listeners.
void execute()
Execute all expired RTSchedulables.
Contains the main loop of openMSX.
RTScheduler & getRTScheduler()
Interpreter & getInterpreter()
InputEventGenerator & getInputEventGenerator()
bool isMainThread()
Returns true when called from the main thread.
This file implemented 3 utility functions:
EventType getType(const Event &event)
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
auto upper_bound(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
auto rfind_unguarded(RANGE &range, const VAL &val, Proj proj={})
Similar to the find(_if)_unguarded functions above, but searches from the back to front.
constexpr bool contains(ITER first, ITER last, const VAL &val)
Check if a range contains a given value, using linear search.