Fix some data races (#890)

This commit is contained in:
Murat Seker
2020-07-22 16:43:24 +02:00
committed by GitHub
parent 6362cfcc1b
commit 126c18e003
8 changed files with 69 additions and 50 deletions

View File

@@ -53,6 +53,9 @@ Effect::Effect(Hyperion *hyperion, int priority, int timeout, const QString &scr
Effect::~Effect()
{
requestInterruption();
wait();
delete _painter;
_imageStack.clear();
}
@@ -82,10 +85,14 @@ void Effect::run()
PyModule_AddObject(module, "__effectObj", PyCapsule_New((void*)this, "hyperion.__effectObj", nullptr));
// add ledCount variable to the interpreter
PyObject_SetAttrString(module, "ledCount", Py_BuildValue("i", _hyperion->getLedCount()));
unsigned ledCount = 0;
QMetaObject::invokeMethod(_hyperion, "getLedCount", Qt::BlockingQueuedConnection, Q_RETURN_ARG(unsigned, ledCount));
PyObject_SetAttrString(module, "ledCount", Py_BuildValue("i", ledCount));
// add minimumWriteTime variable to the interpreter
PyObject_SetAttrString(module, "latchTime", Py_BuildValue("i", _hyperion->getLatchTime()));
int latchTime = 0;
QMetaObject::invokeMethod(_hyperion, "getLatchTime", Qt::BlockingQueuedConnection, Q_RETURN_ARG(int, latchTime));
PyObject_SetAttrString(module, "latchTime", Py_BuildValue("i", latchTime));
// add a args variable to the interpreter
PyObject_SetAttrString(module, "args", EffectModule::json2python(_args));

View File

@@ -144,7 +144,7 @@ PyObject* EffectModule::wrapSetColor(PyObject *self, PyObject *args)
{
getEffect()->_colors.fill(color);
QVector<ColorRgb> _cQV = getEffect()->_colors;
getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), timeout, false);
emit getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), timeout, false);
Py_RETURN_NONE;
}
return nullptr;
@@ -163,7 +163,7 @@ PyObject* EffectModule::wrapSetColor(PyObject *self, PyObject *args)
char * data = PyByteArray_AS_STRING(bytearray);
memcpy(getEffect()->_colors.data(), data, length);
QVector<ColorRgb> _cQV = getEffect()->_colors;
getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), timeout, false);
emit getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), timeout, false);
Py_RETURN_NONE;
}
else
@@ -218,7 +218,7 @@ PyObject* EffectModule::wrapSetImage(PyObject *self, PyObject *args)
Image<ColorRgb> image(width, height);
char * data = PyByteArray_AS_STRING(bytearray);
memcpy(image.memptr(), data, length);
getEffect()->setInputImage(getEffect()->_priority, image, timeout, false);
emit getEffect()->setInputImage(getEffect()->_priority, image, timeout, false);
Py_RETURN_NONE;
}
else
@@ -375,7 +375,7 @@ PyObject* EffectModule::wrapImageShow(PyObject *self, PyObject *args)
}
memcpy(image.memptr(), binaryImage.data(), binaryImage.size());
getEffect()->setInputImage(getEffect()->_priority, image, timeout, false);
emit getEffect()->setInputImage(getEffect()->_priority, image, timeout, false);
return Py_BuildValue("");
}

View File

@@ -54,7 +54,10 @@ void SSDPHandler::initServer()
}
// startup if localAddress is found
if(!_localAddress.isEmpty() && _webserver->isInited())
bool isInited = false;
QMetaObject::invokeMethod(_webserver, "isInited", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, isInited));
if(!_localAddress.isEmpty() && isInited)
{
handleWebServerStateChange(true);
}
@@ -100,14 +103,14 @@ void SSDPHandler::handleWebServerStateChange(const bool newState)
if(newState)
{
// refresh info
_webserver->setSSDPDescription(buildDesc());
QMetaObject::invokeMethod(_webserver, "setSSDPDescription", Qt::BlockingQueuedConnection, Q_ARG(QString, buildDesc()));
setDescriptionAddress(getDescAddress());
if(start())
sendAnnounceList(true);
}
else
{
_webserver->setSSDPDescription("");
QMetaObject::invokeMethod(_webserver, "setSSDPDescription", Qt::BlockingQueuedConnection, Q_ARG(QString, ""));
sendAnnounceList(false);
stop();
}
@@ -124,7 +127,7 @@ void SSDPHandler::handleNetworkConfigurationChanged(const QNetworkConfiguration
// update desc & notify new ip
_localAddress = localAddress;
_webserver->setSSDPDescription(buildDesc());
QMetaObject::invokeMethod(_webserver, "setSSDPDescription", Qt::BlockingQueuedConnection, Q_ARG(QString, buildDesc()));
setDescriptionAddress(getDescAddress());
sendAnnounceList(true);
}
@@ -177,7 +180,9 @@ QString SSDPHandler::getDescAddress() const
QString SSDPHandler::getBaseAddress() const
{
return QString("http://%1:%2/").arg(_localAddress).arg(_webserver->getPort());
quint16 port = 0;
QMetaObject::invokeMethod(_webserver, "getPort", Qt::BlockingQueuedConnection, Q_RETURN_ARG(quint16, port));
return QString("http://%1:%2/").arg(_localAddress).arg(port);
}
QString SSDPHandler::buildDesc() const
@@ -195,3 +200,4 @@ void SSDPHandler::sendAnnounceList(const bool alive)
alive ? SSDPServer::sendAlive(entry) : SSDPServer::sendByeBye(entry);
}
}

View File

@@ -12,7 +12,6 @@
// netUtil
#include <utils/NetUtils.h>
WebServer::WebServer(const QJsonDocument& config, const bool& useSsl, QObject * parent)
: QObject(parent)
, _config(config)