Commit 6cd122f9 authored by Jan Möbius's avatar Jan Möbius

Switched QMutex for OpenFlipperThread startup to QSemaphore to be able to call...

Switched QMutex for OpenFlipperThread startup to QSemaphore to be able to call it across processes. Otherwise Windows Qt crashes in debug mode. Removed debug output

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9057 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0be66c8b
......@@ -38,12 +38,9 @@ OpenFlipperThread::OpenFlipperThread( QString _jobId ) :
job_(0),
jobId_(_jobId)
{
startup_.lock();
}
OpenFlipperThread::~OpenFlipperThread() {
std::cerr << "Destructor Thread" << std::endl;
}
void OpenFlipperThread::run()
......@@ -62,17 +59,13 @@ void OpenFlipperThread::run()
// connect the function to start the job
connect(this,SIGNAL(startProcessingInternal()),job_,SLOT(startJobProcessing()),Qt::QueuedConnection);
}
std::cerr << "Start Event Loop" << std::endl;
startup_.unlock();
// Start event queue
// Thread is ready for processing now, tell core that we can continue.
startup_.release(1);
// Start event queue (possibly added events are already queued here
exec();
std::cerr << "End Event Loop " << std::endl;
// TODO: Self destuction sometimes does not work!
// Seems to be a race condition!!!
......@@ -102,25 +95,20 @@ void OpenFlipperThread::slotJobFinished( ) {
void OpenFlipperThread::startProcessing() {
std::cerr << "Thread emit startProcessing" << std::endl;
// Wait for thread to come up with event loop ... otherwise the signals might get lost
startup_.lock();
// Wait for thread to come up and connect its signals ... otherwise the signals might get lost
startup_.acquire(1);
// Tell internal wrapper to start with the processing
emit startProcessingInternal();
startup_.unlock();
std::cerr << "Thread emit startProcessing done" << std::endl;
}
OpenFlipperJob::~OpenFlipperJob()
{
std::cerr << "Destructor job called" << std::endl;
}
void OpenFlipperJob::startJobProcessing() {
std::cerr << "job start process" << std::endl;
// Actually start the process ( This function will block as it uses a direct connection )
// But it only blocks the current thread.
emit process();
......@@ -130,6 +118,4 @@ void OpenFlipperJob::startJobProcessing() {
// Cleanup this object
deleteLater();
std::cerr << "processing done" << std::endl;
}
......@@ -34,7 +34,7 @@
#define OPENFLIPPERTHREAD_HH
#include <QThread>
#include <QMutex>
#include <QSemaphore>
#include <OpenFlipper/common/GlobalDefines.hh>
......@@ -221,7 +221,15 @@ class DLLEXPORT OpenFlipperThread : public QThread
*/
QString jobId_;
QMutex startup_;
/** \brief Semaphore to control order of thread startup calls
*
* This variable is used to control the order of thread startup calls. The Thread itself is
* started, and when it is up and running, the resource will be created. The core thread waits
* for this resource and afterwards starts execution of the threads processing function.
* Without this sync, the processing call of the main thread might get lost as the thread is
* not online and listening for the signal.
*/
QSemaphore startup_;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment