From 935759373a683189004ff7f6e063aca7549083f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Fri, 31 May 2024 11:42:14 -0300 Subject: [PATCH] [osx] Fix events handling (fix #89) --- os/osx/event_queue.h | 5 ++--- os/osx/event_queue.mm | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/os/osx/event_queue.h b/os/osx/event_queue.h index a6b96736f..74d74998b 100644 --- a/os/osx/event_queue.h +++ b/os/osx/event_queue.h @@ -13,8 +13,6 @@ #include "os/event.h" #include "os/event_queue.h" -#include - namespace os { class EventQueueOSX : public EventQueue { @@ -29,7 +27,8 @@ class EventQueueOSX : public EventQueue { void wakeUpQueue(); base::concurrent_queue m_events; - std::atomic m_sleeping; + mutable std::mutex m_mutex; + bool m_sleeping; }; using EventQueueImpl = EventQueueOSX; diff --git a/os/osx/event_queue.mm b/os/osx/event_queue.mm index 419fb2949..51d11cb1e 100644 --- a/os/osx/event_queue.mm +++ b/os/osx/event_queue.mm @@ -74,17 +74,21 @@ } } while (event); + m_mutex.lock(); if (!m_events.try_pop(ev)) { if (timeout == kWithoutTimeout) EV_TRACE("EV: Waiting for events\n"); // Wait until there is a Cocoa event in queue m_sleeping = true; + m_mutex.unlock(); event = [app nextEventMatchingMask:NSEventMaskAny untilDate:untilDate inMode:NSDefaultRunLoopMode dequeue:YES]; + m_mutex.lock(); m_sleeping = false; + m_mutex.unlock(); if (event) { EV_TRACE("EV: Event received!\n"); @@ -94,11 +98,13 @@ EV_TRACE("EV: Timeout!"); } } + m_mutex.unlock(); } } void EventQueueOSX::queueEvent(const Event& ev) { + const std::lock_guard lock(m_mutex); if (m_sleeping) { // Wake up the macOS event queue. This is necessary in case that we // change the display color profile from macOS settings: the