Commit d5e3f649 authored by Augustin Degomme's avatar Augustin Degomme

use QMutexLocker to handle threading issues with QMutexes and avoid assertion failures on windows

parent 6351b288
......@@ -333,9 +333,9 @@ bool Core::draw_trace(const string & filename, const int format) {
//#else
// sleep(1); // We wait 1 second
if(!parser->is_end_of_parsing()){
mutex.lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(&mutex);
finished.wait(&mutex, 1000);
mutex.unlock();
}
loaded_f = parser->get_percent_loaded();
loaded = (int)(loaded_f*100.0f);
......@@ -362,8 +362,9 @@ bool Core::draw_trace(const string & filename, const int format) {
_trace->updateTrace(i);
}
}else{
#endif
mutex.lock();
#endif
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(&mutex);
if(format != _STATE_SPLITTING) {
emit build_finished();
......@@ -385,11 +386,10 @@ bool Core::draw_trace(const string & filename, const int format) {
}
#if defined(USE_ITC) && defined(BOOST_SERIALIZE)
finished.wait(&mutex);
}
#endif
mutex.unlock();
}
cout << QObject::tr("Loading of the trace : ").toStdString() << loaded << "%" ;
......@@ -422,10 +422,10 @@ bool Core::draw_trace(const string & filename, const int format) {
cout << QObject::tr("Canceled at ").toStdString() << loaded << "%" << endl;
parser->set_canceled();
*Message::get_instance() << QObject::tr("The trace opening was canceled by the user at ").toStdString() << loaded << "%" << Message::ende;
mutex.lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(&mutex);
emit build_finished();
finished.wait(&mutex);
mutex.unlock();
break; // Quit the loop
}
}
......
......@@ -100,15 +100,16 @@ bool BuilderThread::is_finished(){return _is_finished;}
void BuilderThread::finish_build(){
//quit();
//finish the TraceBuilderThread before closing this one
_mutex2->lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker2(_mutex2);
emit build_finished();
_trace_cond->wait(_mutex2);
_mutex2->unlock();
locker2.unlock();
_is_finished=true;
_mutex->lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(_mutex);
_cond->wakeAll();
_mutex->unlock();
}
......@@ -69,10 +69,9 @@ void ParsingThread::run() {
catch (const std::string &) {
_parser->finish();
}
_mutex->lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(_mutex);
_finished->wakeAll();
_mutex->unlock();
}
......@@ -80,9 +79,9 @@ void ParsingThread::finish_build(){
_is_finished=true;
_trace->finish();
_mutex->lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(_mutex);
_finished->wakeAll();
_mutex->unlock();
}
void ParsingThread::dump(std::string path, std::string filename){
......@@ -90,8 +89,8 @@ void ParsingThread::dump(std::string path, std::string filename){
#if defined(USE_ITC) && defined(BOOST_SERIALIZE)
_trace->dump(path, filename);
#endif
_mutex->lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(_mutex);
_finished->wakeAll();
_mutex->unlock();
}
......@@ -241,10 +241,11 @@ void mt_ParserPaje::parse(Trace &trace,
line=NULL;
//send the finish signal to the BuilderThread, which will do the same to the TraceBuilderThread
//both threads will then be finished and ready to destroy
mutex.lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(&mutex);
emit build_finish();
ended.wait(&mutex);
mutex.unlock();
locker.unlock();
traceBuilderThread.quit();
traceBuilderThread.wait();
consumerThread.quit();
......
......@@ -70,11 +70,12 @@ void SerializerDispatcher::kill_all_threads(){
_evt_array[i].connect((const QObject*)this,
SIGNAL(build_finish()),
SLOT(finish_build()));
_mutex->lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(_mutex);
emit build_finish();
QWaitCondition* _cond=_evt_array[i].get_cond();
_cond->wait(_mutex);
_mutex->unlock();
locker.unlock();
_evt_array[i].get_thread()->quit();
}
......
......@@ -76,10 +76,10 @@ void SerializerWriter::dump_on_disk(IntervalOfContainer* itc,const char* filenam
bool SerializerWriter::is_finished(){return _is_finished;}
void SerializerWriter::finish_build(){
// printf("répondons : %p _this %p %p\n", _thread,this, _cond);
_mutex->lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(_mutex);
_is_finished=true;
_cond->wakeAll();
_mutex->unlock();
}
......@@ -44,10 +44,10 @@ TraceBuilderThread::TraceBuilderThread(QWaitCondition* cond, QSemaphore * freeS
}
void TraceBuilderThread::build_finished(){
_mutex->lock();
//locks the mutex and automatically unlocks it when going out of scope
QMutexLocker locker(_mutex);
_is_finished=true;
_cond->wakeAll();
_mutex->unlock();
}
void TraceBuilderThread::define_container_type(Trace_builder_struct* tb_struct){
......
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