lib/platform: Use standard mutex primitives in X server event queue

This commit is contained in:
Povilas Kanapickas 2021-11-03 02:58:34 +02:00
parent 391c34d669
commit 9df64f36e3
2 changed files with 9 additions and 10 deletions

View File

@ -18,7 +18,6 @@
#include "platform/XWindowsEventQueueBuffer.h" #include "platform/XWindowsEventQueueBuffer.h"
#include "mt/Lock.h"
#include "mt/Thread.h" #include "mt/Thread.h"
#include "base/Event.h" #include "base/Event.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
@ -84,7 +83,7 @@ XWindowsEventQueueBuffer::~XWindowsEventQueueBuffer()
int XWindowsEventQueueBuffer::getPendingCountLocked() int XWindowsEventQueueBuffer::getPendingCountLocked()
{ {
Lock lock(&m_mutex); std::lock_guard<std::mutex> lock(mutex_);
// work around a bug in old libx11 which causes the first XPending not to read events under // work around a bug in old libx11 which causes the first XPending not to read events under
// certain conditions. The issue happens when libx11 has not yet received replies for all // certain conditions. The issue happens when libx11 has not yet received replies for all
// flushed events. In that case, internally XPending will not try to process received events // flushed events. In that case, internally XPending will not try to process received events
@ -112,7 +111,7 @@ XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
} }
{ {
Lock lock(&m_mutex); std::lock_guard<std::mutex> lock(mutex_);
// we're now waiting for events // we're now waiting for events
m_waiting = true; m_waiting = true;
@ -204,7 +203,7 @@ XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
{ {
// we're no longer waiting for events // we're no longer waiting for events
Lock lock(&m_mutex); std::lock_guard<std::mutex> lock(mutex_);
m_waiting = false; m_waiting = false;
} }
@ -214,7 +213,7 @@ XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
IEventQueueBuffer::Type IEventQueueBuffer::Type
XWindowsEventQueueBuffer::getEvent(Event& event, UInt32& dataID) XWindowsEventQueueBuffer::getEvent(Event& event, UInt32& dataID)
{ {
Lock lock(&m_mutex); std::lock_guard<std::mutex> lock(mutex_);
// push out pending events // push out pending events
flush(); flush();
@ -247,7 +246,7 @@ XWindowsEventQueueBuffer::addEvent(UInt32 dataID)
xevent.xclient.data.l[0] = static_cast<long>(dataID); xevent.xclient.data.l[0] = static_cast<long>(dataID);
// save the message // save the message
Lock lock(&m_mutex); std::lock_guard<std::mutex> lock(mutex_);
m_postedEvents.push_back(xevent); m_postedEvents.push_back(xevent);
// if we're currently waiting for an event then send saved events to // if we're currently waiting for an event then send saved events to
@ -275,7 +274,7 @@ XWindowsEventQueueBuffer::addEvent(UInt32 dataID)
bool bool
XWindowsEventQueueBuffer::isEmpty() const XWindowsEventQueueBuffer::isEmpty() const
{ {
Lock lock(&m_mutex); std::lock_guard<std::mutex> lock(mutex_);
return (m_impl->XPending(m_display) == 0 ); return (m_impl->XPending(m_display) == 0 );
} }
@ -294,7 +293,7 @@ XWindowsEventQueueBuffer::deleteTimer(EventQueueTimer* timer) const
void void
XWindowsEventQueueBuffer::flush() XWindowsEventQueueBuffer::flush()
{ {
// note -- m_mutex must be locked on entry // note -- mutex_ must be locked on entry
// flush the posted event list to the X server // flush the posted event list to the X server
for (size_t i = 0; i < m_postedEvents.size(); ++i) { for (size_t i = 0; i < m_postedEvents.size(); ++i) {

View File

@ -18,12 +18,12 @@
#pragma once #pragma once
#include "mt/Mutex.h"
#include "base/IEventQueueBuffer.h" #include "base/IEventQueueBuffer.h"
#include "common/stdvector.h" #include "common/stdvector.h"
#include "XWindowsImpl.h" #include "XWindowsImpl.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <mutex>
class IEventQueue; class IEventQueue;
@ -53,7 +53,7 @@ private:
typedef std::vector<XEvent> EventList; typedef std::vector<XEvent> EventList;
IXWindowsImpl* m_impl; IXWindowsImpl* m_impl;
Mutex m_mutex; mutable std::mutex mutex_;
Display* m_display; Display* m_display;
Window m_window; Window m_window;
Atom m_userEvent; Atom m_userEvent;