committed by
Nick Bolton
parent
f4618ee085
commit
e247f3813a
@ -29,7 +29,6 @@ static void interrupt(Arch::ESignal, void *data)
|
||||
|
||||
EventQueue::EventQueue() : m_readyMutex(new Mutex), m_readyCondVar(new CondVar<bool>(m_readyMutex, false))
|
||||
{
|
||||
m_mutex = ARCH->newMutex();
|
||||
ARCH->setSignalHandler(Arch::kINTERRUPT, &interrupt, this);
|
||||
ARCH->setSignalHandler(Arch::kTERMINATE, &interrupt, this);
|
||||
m_buffer = std::make_unique<SimpleEventQueueBuffer>();
|
||||
@ -42,7 +41,6 @@ EventQueue::~EventQueue()
|
||||
|
||||
ARCH->setSignalHandler(Arch::kINTERRUPT, nullptr, nullptr);
|
||||
ARCH->setSignalHandler(Arch::kTERMINATE, nullptr, nullptr);
|
||||
ARCH->closeMutex(m_mutex);
|
||||
}
|
||||
|
||||
void EventQueue::loop()
|
||||
@ -72,7 +70,7 @@ void EventQueue::loop()
|
||||
|
||||
void EventQueue::adoptBuffer(IEventQueueBuffer *buffer)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
LOG((CLOG_DEBUG "adopting new buffer"));
|
||||
|
||||
@ -141,7 +139,7 @@ bool EventQueue::processEvent(Event &event, double timeout, Stopwatch &timer)
|
||||
return true;
|
||||
|
||||
case IEventQueueBuffer::kUser: {
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
event = removeEvent(dataID);
|
||||
return true;
|
||||
}
|
||||
@ -197,7 +195,7 @@ void EventQueue::addEvent(const Event &event)
|
||||
|
||||
void EventQueue::addEventToBuffer(const Event &event)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
// store the event's data locally
|
||||
auto eventID = saveEvent(event);
|
||||
@ -218,7 +216,7 @@ EventQueueTimer *EventQueue::newTimer(double duration, void *target)
|
||||
if (target == nullptr) {
|
||||
target = timer;
|
||||
}
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_timers.insert(timer);
|
||||
// initial duration is requested duration plus whatever's on
|
||||
// the clock currently because the latter will be subtracted
|
||||
@ -235,7 +233,7 @@ EventQueueTimer *EventQueue::newOneShotTimer(double duration, void *target)
|
||||
if (target == nullptr) {
|
||||
target = timer;
|
||||
}
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_timers.insert(timer);
|
||||
// initial duration is requested duration plus whatever's on
|
||||
// the clock currently because the latter will be subtracted
|
||||
@ -246,7 +244,7 @@ EventQueueTimer *EventQueue::newOneShotTimer(double duration, void *target)
|
||||
|
||||
void EventQueue::deleteTimer(EventQueueTimer *timer)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
for (auto index = m_timerQueue.begin(); index != m_timerQueue.end(); ++index) {
|
||||
if (index->getTimer() == timer) {
|
||||
m_timerQueue.erase(index);
|
||||
@ -261,7 +259,7 @@ void EventQueue::deleteTimer(EventQueueTimer *timer)
|
||||
|
||||
void EventQueue::adoptHandler(EventTypes type, void *target, IEventJob *handler)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_handlers[target][type].reset(handler);
|
||||
}
|
||||
|
||||
@ -269,7 +267,7 @@ void EventQueue::removeHandler(EventTypes type, void *target)
|
||||
{
|
||||
std::unique_ptr<IEventJob> handler;
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
HandlerTable::iterator index = m_handlers.find(target);
|
||||
if (index != m_handlers.end()) {
|
||||
TypeHandlerTable &typeHandlers = index->second;
|
||||
@ -287,7 +285,7 @@ void EventQueue::removeHandlers(void *target)
|
||||
{
|
||||
std::vector<std::unique_ptr<IEventJob>> handlers;
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
HandlerTable::iterator index = m_handlers.find(target);
|
||||
if (index != m_handlers.end()) {
|
||||
// copy to handlers array and clear table for target
|
||||
@ -308,7 +306,7 @@ bool EventQueue::isEmpty() const
|
||||
|
||||
IEventJob *EventQueue::getHandler(EventTypes type, void *target) const
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (HandlerTable::const_iterator index = m_handlers.find(target); index != m_handlers.end()) {
|
||||
const TypeHandlerTable &typeHandlers = index->second;
|
||||
TypeHandlerTable::const_iterator index2 = typeHandlers.find(type);
|
||||
|
||||
@ -15,11 +15,10 @@
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
|
||||
class Mutex;
|
||||
|
||||
//! Event queue
|
||||
/*!
|
||||
An event queue that implements the platform independent parts and
|
||||
@ -104,7 +103,7 @@ private:
|
||||
using HandlerTable = std::map<void *, TypeHandlerTable>;
|
||||
|
||||
int m_systemTarget = 0;
|
||||
ArchMutex m_mutex;
|
||||
mutable std::mutex m_mutex;
|
||||
|
||||
// buffer of events
|
||||
std::unique_ptr<IEventQueueBuffer> m_buffer;
|
||||
|
||||
Reference in New Issue
Block a user