Revision of mutex locks in FIFOs

pull/875/head
f4exb 2021-04-26 19:33:02 +02:00
rodzic 3792398c8b
commit e3910c0aa1
6 zmienionych plików z 30 dodań i 17 usunięć

Wyświetl plik

@ -31,6 +31,7 @@ void DataFifo::create(unsigned int s)
void DataFifo::reset()
{
QMutexLocker mutexLocker(&m_mutex);
m_suppressed = -1;
m_fill = 0;
m_head = 0;
@ -39,7 +40,8 @@ void DataFifo::reset()
DataFifo::DataFifo(QObject* parent) :
QObject(parent),
m_data()
m_data(),
m_mutex(QMutex::Recursive)
{
m_suppressed = -1;
m_size = 0;
@ -50,7 +52,8 @@ DataFifo::DataFifo(QObject* parent) :
DataFifo::DataFifo(int size, QObject* parent) :
QObject(parent),
m_data()
m_data(),
m_mutex(QMutex::Recursive)
{
m_suppressed = -1;
create(size);
@ -58,7 +61,8 @@ DataFifo::DataFifo(int size, QObject* parent) :
DataFifo::DataFifo(const DataFifo& other) :
QObject(other.parent()),
m_data(other.m_data)
m_data(other.m_data),
m_mutex(QMutex::Recursive)
{
m_suppressed = -1;
m_size = m_data.size();
@ -75,8 +79,8 @@ DataFifo::~DataFifo()
bool DataFifo::setSize(int size)
{
QMutexLocker mutexLocker(&m_mutex);
create(size);
return m_data.size() == size;
}

Wyświetl plik

@ -31,11 +31,10 @@ class SDRBASE_API DataFifo : public QObject {
Q_OBJECT
private:
QMutex m_mutex;
QElapsedTimer m_msgRateTimer;
int m_suppressed;
QByteArray m_data;
QMutex m_mutex;
unsigned int m_size;
unsigned int m_fill;

Wyświetl plik

@ -19,6 +19,7 @@
void SampleMIFifo::init(unsigned int nbStreams, unsigned int size)
{
QMutexLocker mutexLocker(&m_mutex);
m_nbStreams = nbStreams;
m_size = size;
m_fill = 0;
@ -52,12 +53,14 @@ SampleMIFifo::SampleMIFifo(QObject *parent) :
m_nbStreams(0),
m_size(0),
m_fill(0),
m_head(0)
m_head(0),
m_mutex(QMutex::Recursive)
{
}
SampleMIFifo::SampleMIFifo(unsigned int nbStreams, unsigned int size, QObject *parent) :
QObject(parent)
QObject(parent),
m_mutex(QMutex::Recursive)
{
init(nbStreams, size);
}
@ -235,6 +238,8 @@ void SampleMIFifo::readSync(
return;
}
QMutexLocker mutexLocker(&m_mutex);
if (m_head < m_fill)
{
ipart1Begin = m_head;

Wyświetl plik

@ -27,13 +27,15 @@ SampleMOFifo::SampleMOFifo(QObject *parent) :
{}
SampleMOFifo::SampleMOFifo(unsigned int nbStreams, unsigned int size, QObject *parent) :
QObject(parent)
QObject(parent),
m_mutex(QMutex::Recursive)
{
init(nbStreams, size);
}
void SampleMOFifo::init(unsigned int nbStreams, unsigned int size)
{
QMutexLocker mutexLocker(&m_mutex);
m_data.resize(nbStreams);
m_vReadCount.resize(nbStreams);
m_vReadHead.resize(nbStreams);
@ -231,4 +233,4 @@ void SampleMOFifo::writeAsync( //!< in place write with given amount
unsigned int SampleMOFifo::getSizePolicy(unsigned int sampleRate)
{
return (sampleRate/100)*64; // .64s
}
}

Wyświetl plik

@ -32,6 +32,7 @@ void SampleSinkFifo::create(unsigned int s)
void SampleSinkFifo::reset()
{
QMutexLocker mutexLocker(&m_mutex);
m_suppressed = -1;
m_fill = 0;
m_head = 0;
@ -40,7 +41,8 @@ void SampleSinkFifo::reset()
SampleSinkFifo::SampleSinkFifo(QObject* parent) :
QObject(parent),
m_data()
m_data(),
m_mutex(QMutex::Recursive)
{
m_suppressed = -1;
m_size = 0;
@ -51,7 +53,8 @@ SampleSinkFifo::SampleSinkFifo(QObject* parent) :
SampleSinkFifo::SampleSinkFifo(int size, QObject* parent) :
QObject(parent),
m_data()
m_data(),
m_mutex(QMutex::Recursive)
{
m_suppressed = -1;
create(size);
@ -59,7 +62,8 @@ SampleSinkFifo::SampleSinkFifo(int size, QObject* parent) :
SampleSinkFifo::SampleSinkFifo(const SampleSinkFifo& other) :
QObject(other.parent()),
m_data(other.m_data)
m_data(other.m_data),
m_mutex(QMutex::Recursive)
{
m_suppressed = -1;
m_size = m_data.size();
@ -76,8 +80,8 @@ SampleSinkFifo::~SampleSinkFifo()
bool SampleSinkFifo::setSize(int size)
{
QMutexLocker mutexLocker(&m_mutex);
create(size);
return m_data.size() == (unsigned int)size;
}

Wyświetl plik

@ -29,11 +29,10 @@ class SDRBASE_API SampleSinkFifo : public QObject {
Q_OBJECT
private:
QMutex m_mutex;
QElapsedTimer m_msgRateTimer;
int m_suppressed;
SampleVector m_data;
QMutex m_mutex;
unsigned int m_size;
unsigned int m_fill;
@ -50,7 +49,7 @@ public:
bool setSize(int size);
void reset();
inline unsigned int size() const { return m_size; }
inline unsigned int size() { QMutexLocker mutexLocker(&m_mutex); unsigned int size = m_size; return size; }
inline unsigned int fill() { QMutexLocker mutexLocker(&m_mutex); unsigned int fill = m_fill; return fill; }
unsigned int write(const quint8* data, unsigned int count);