lib/base: Use standard mutex primitives in event queue buffer
This commit is contained in:
parent
cb69469871
commit
27de30e761
|
@ -28,21 +28,17 @@ class EventQueueTimer { };
|
||||||
|
|
||||||
SimpleEventQueueBuffer::SimpleEventQueueBuffer()
|
SimpleEventQueueBuffer::SimpleEventQueueBuffer()
|
||||||
{
|
{
|
||||||
m_queueMutex = ARCH->newMutex();
|
|
||||||
m_queueReadyCond = ARCH->newCondVar();
|
|
||||||
m_queueReady = false;
|
m_queueReady = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleEventQueueBuffer::~SimpleEventQueueBuffer()
|
SimpleEventQueueBuffer::~SimpleEventQueueBuffer()
|
||||||
{
|
{
|
||||||
ARCH->closeCondVar(m_queueReadyCond);
|
|
||||||
ARCH->closeMutex(m_queueMutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SimpleEventQueueBuffer::waitForEvent(double timeout)
|
SimpleEventQueueBuffer::waitForEvent(double timeout)
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_queueMutex);
|
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||||
Stopwatch timer(true);
|
Stopwatch timer(true);
|
||||||
while (!m_queueReady) {
|
while (!m_queueReady) {
|
||||||
double timeLeft = timeout;
|
double timeLeft = timeout;
|
||||||
|
@ -52,14 +48,14 @@ SimpleEventQueueBuffer::waitForEvent(double timeout)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ARCH->waitCondVar(m_queueReadyCond, lock, timeLeft);
|
ARCH->wait_cond_var(queue_ready_cv_, lock, timeLeft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IEventQueueBuffer::Type
|
IEventQueueBuffer::Type
|
||||||
SimpleEventQueueBuffer::getEvent(Event&, UInt32& dataID)
|
SimpleEventQueueBuffer::getEvent(Event&, UInt32& dataID)
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_queueMutex);
|
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||||
if (!m_queueReady) {
|
if (!m_queueReady) {
|
||||||
return kNone;
|
return kNone;
|
||||||
}
|
}
|
||||||
|
@ -72,11 +68,11 @@ SimpleEventQueueBuffer::getEvent(Event&, UInt32& dataID)
|
||||||
bool
|
bool
|
||||||
SimpleEventQueueBuffer::addEvent(UInt32 dataID)
|
SimpleEventQueueBuffer::addEvent(UInt32 dataID)
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_queueMutex);
|
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||||
m_queue.push_front(dataID);
|
m_queue.push_front(dataID);
|
||||||
if (!m_queueReady) {
|
if (!m_queueReady) {
|
||||||
m_queueReady = true;
|
m_queueReady = true;
|
||||||
ARCH->broadcastCondVar(m_queueReadyCond);
|
queue_ready_cv_.notify_all();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +80,7 @@ SimpleEventQueueBuffer::addEvent(UInt32 dataID)
|
||||||
bool
|
bool
|
||||||
SimpleEventQueueBuffer::isEmpty() const
|
SimpleEventQueueBuffer::isEmpty() const
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_queueMutex);
|
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||||
return !m_queueReady;
|
return !m_queueReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "base/IEventQueueBuffer.h"
|
#include "base/IEventQueueBuffer.h"
|
||||||
#include "arch/IArchMultithread.h"
|
#include "arch/IArchMultithread.h"
|
||||||
#include "common/stddeque.h"
|
#include "common/stddeque.h"
|
||||||
|
#include <condition_variable>
|
||||||
|
|
||||||
//! In-memory event queue buffer
|
//! In-memory event queue buffer
|
||||||
/*!
|
/*!
|
||||||
|
@ -44,8 +45,8 @@ public:
|
||||||
private:
|
private:
|
||||||
typedef std::deque<UInt32> EventDeque;
|
typedef std::deque<UInt32> EventDeque;
|
||||||
|
|
||||||
ArchMutex m_queueMutex;
|
mutable std::mutex queue_mutex_;
|
||||||
ArchCond m_queueReadyCond;
|
std::condition_variable queue_ready_cv_;
|
||||||
bool m_queueReady;
|
bool m_queueReady;
|
||||||
EventDeque m_queue;
|
EventDeque m_queue;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue