1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-06 16:05:13 -04:00

Deep redesign: phase #2

This commit is contained in:
f4exb
2015-08-14 05:00:28 +02:00
parent 1799cd816f
commit f5c5e19571
27 changed files with 592 additions and 550 deletions
+19 -51
View File
@@ -1,3 +1,20 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 F4EXB //
// written by Edouard Griffiths //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QWaitCondition>
#include <QMutex>
#include "util/message.h"
@@ -6,20 +23,12 @@
const char* Message::m_identifier = "Message";
Message::Message() :
m_destination(NULL),
m_synchronous(false),
m_waitCondition(NULL),
m_mutex(NULL),
m_complete(0)
m_destination(0)
{
}
Message::~Message()
{
if(m_waitCondition != NULL)
delete m_waitCondition;
if(m_mutex != NULL)
delete m_mutex;
}
const char* Message::getIdentifier() const
@@ -32,48 +41,7 @@ bool Message::matchIdentifier(const char* identifier) const
return m_identifier == identifier;
}
bool Message::match(Message* message)
bool Message::match(const Message* message)
{
return message->matchIdentifier(m_identifier);
}
void Message::submit(MessageQueue* queue, void* destination)
{
m_destination = destination;
m_synchronous = false;
queue->submit(this);
}
int Message::execute(MessageQueue* queue, void* destination)
{
m_destination = destination;
m_synchronous = true;
if(m_waitCondition == NULL)
m_waitCondition = new QWaitCondition;
if(m_mutex == NULL)
m_mutex = new QMutex;
m_mutex->lock();
m_complete.testAndSetAcquire(0, 1);
queue->submit(this);
while(!m_complete.testAndSetAcquire(0, 1))
((QWaitCondition*)m_waitCondition)->wait(m_mutex, 100);
m_complete = 0;
int result = m_result;
m_mutex->unlock();
return result;
}
void Message::completed(int result)
{
if(m_synchronous) {
m_result = result;
m_complete = 0;
if(m_waitCondition == NULL)
qFatal("wait condition is NULL");
m_waitCondition->wakeAll();
} else {
delete this;
}
}