refactor: use std::mutex in platform/XWindowsEventQueue
This commit is contained in:
parent
5686d24626
commit
782702fe74
2 changed files with 8 additions and 9 deletions
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
#include "base/Event.h"
|
#include "base/Event.h"
|
||||||
#include "base/IEventQueue.h"
|
#include "base/IEventQueue.h"
|
||||||
#include "mt/Lock.h"
|
|
||||||
#include "mt/Thread.h"
|
#include "mt/Thread.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
@ -51,7 +50,7 @@ XWindowsEventQueueBuffer::~XWindowsEventQueueBuffer()
|
||||||
|
|
||||||
int XWindowsEventQueueBuffer::getPendingCountLocked()
|
int XWindowsEventQueueBuffer::getPendingCountLocked()
|
||||||
{
|
{
|
||||||
Lock lock(&m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
return XPending(m_display);
|
return XPending(m_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +68,7 @@ void XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Lock lock(&m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
// we're now waiting for events
|
// we're now waiting for events
|
||||||
m_waiting = true;
|
m_waiting = true;
|
||||||
|
|
||||||
|
|
@ -123,7 +122,7 @@ void 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(m_mutex);
|
||||||
m_waiting = false;
|
m_waiting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,7 +131,7 @@ void XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
|
||||||
|
|
||||||
IEventQueueBuffer::Type XWindowsEventQueueBuffer::getEvent(Event &event, uint32_t &dataID)
|
IEventQueueBuffer::Type XWindowsEventQueueBuffer::getEvent(Event &event, uint32_t &dataID)
|
||||||
{
|
{
|
||||||
Lock lock(&m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
// push out pending events
|
// push out pending events
|
||||||
flush();
|
flush();
|
||||||
|
|
@ -161,7 +160,7 @@ bool XWindowsEventQueueBuffer::addEvent(uint32_t 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(m_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
|
||||||
|
|
@ -187,7 +186,7 @@ bool XWindowsEventQueueBuffer::addEvent(uint32_t dataID)
|
||||||
|
|
||||||
bool XWindowsEventQueueBuffer::isEmpty() const
|
bool XWindowsEventQueueBuffer::isEmpty() const
|
||||||
{
|
{
|
||||||
Lock lock(&m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
return (XPending(m_display) == 0);
|
return (XPending(m_display) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "base/IEventQueueBuffer.h"
|
#include "base/IEventQueueBuffer.h"
|
||||||
#include "mt/Mutex.h"
|
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
@ -47,7 +47,7 @@ private:
|
||||||
private:
|
private:
|
||||||
using EventList = std::vector<XEvent>;
|
using EventList = std::vector<XEvent>;
|
||||||
|
|
||||||
Mutex m_mutex;
|
mutable std::mutex m_mutex;
|
||||||
Display *m_display;
|
Display *m_display;
|
||||||
Window m_window;
|
Window m_window;
|
||||||
Atom m_userEvent;
|
Atom m_userEvent;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue