lib/barrier: Use standard mutex primitives in PacketStreamFilter

This commit is contained in:
Povilas Kanapickas 2021-11-03 02:58:38 +02:00
parent 78c652da42
commit cdbf0dc15c
2 changed files with 11 additions and 11 deletions

View File

@ -19,7 +19,6 @@
#include "barrier/PacketStreamFilter.h"
#include "barrier/protocol_types.h"
#include "base/IEventQueue.h"
#include "mt/Lock.h"
#include "base/TMethodEventJob.h"
#include <cstring>
@ -46,7 +45,7 @@ PacketStreamFilter::~PacketStreamFilter()
void
PacketStreamFilter::close()
{
Lock lock(&m_mutex);
std::lock_guard<std::mutex> lock(mutex_);
m_size = 0;
m_buffer.pop(m_buffer.getSize());
StreamFilter::close();
@ -59,7 +58,7 @@ PacketStreamFilter::read(void* buffer, UInt32 n)
return 0;
}
Lock lock(&m_mutex);
std::lock_guard<std::mutex> lock(mutex_);
// if not enough data yet then give up
if (!isReadyNoLock()) {
@ -108,7 +107,7 @@ PacketStreamFilter::write(const void* buffer, UInt32 count)
void
PacketStreamFilter::shutdownInput()
{
Lock lock(&m_mutex);
std::lock_guard<std::mutex> lock(mutex_);
m_size = 0;
m_buffer.pop(m_buffer.getSize());
StreamFilter::shutdownInput();
@ -117,14 +116,14 @@ PacketStreamFilter::shutdownInput()
bool
PacketStreamFilter::isReady() const
{
Lock lock(&m_mutex);
std::lock_guard<std::mutex> lock(mutex_);
return isReadyNoLock();
}
UInt32
PacketStreamFilter::getSize() const
{
Lock lock(&m_mutex);
std::lock_guard<std::mutex> lock(mutex_);
return isReadyNoLock() ? m_size : 0;
}
@ -136,7 +135,7 @@ PacketStreamFilter::isReadyNoLock() const
bool PacketStreamFilter::readPacketSize()
{
// note -- m_mutex must be locked on entry
// note -- mutex_ must be locked on entry
if (m_size == 0 && m_buffer.getSize() >= 4) {
UInt8 buffer[4];
@ -189,14 +188,14 @@ void
PacketStreamFilter::filterEvent(const Event& event)
{
if (event.getType() == m_events->forIStream().inputReady()) {
Lock lock(&m_mutex);
std::lock_guard<std::mutex> lock(mutex_);
if (!readMore()) {
return;
}
}
else if (event.getType() == m_events->forIStream().inputShutdown()) {
// discard this if we have buffered data
Lock lock(&m_mutex);
std::lock_guard<std::mutex> lock(mutex_);
m_inputShutdown = true;
if (m_size != 0) {
return;

View File

@ -20,7 +20,8 @@
#include "io/StreamFilter.h"
#include "io/StreamBuffer.h"
#include "mt/Mutex.h"
#include <mutex>
class IEventQueue;
@ -53,7 +54,7 @@ private:
bool readMore();
private:
Mutex m_mutex;
mutable std::mutex mutex_;
UInt32 m_size;
StreamBuffer m_buffer;
bool m_inputShutdown;