From 8603a339e762cf384120951ea7c886ebd24972d1 Mon Sep 17 00:00:00 2001 From: Teuniz Date: Sun, 9 Jul 2017 14:32:25 +0200 Subject: [PATCH] Replace QMutex with POSIX threads. --- global.h | 6 +++--- mainwindow.cpp | 23 ++++++++++++----------- mainwindow.h | 1 + mainwindow_constr.cpp | 4 ++-- timer_handlers.cpp | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/global.h b/global.h index 226148f..7c6bdac 100644 --- a/global.h +++ b/global.h @@ -29,13 +29,13 @@ #ifndef DSR_GLOBAL_H #define DSR_GLOBAL_H -#include +#include #include "third_party/kiss_fft/kiss_fftr.h" #define PROGRAM_NAME "DSRemote" -#define PROGRAM_VERSION "0.35_1707091423" +#define PROGRAM_VERSION "0.35_1707091429" #define MAX_PATHLEN 4096 @@ -245,7 +245,7 @@ struct device_settings int screenupdates_on; - QMutex *mutexx; + pthread_mutex_t mutexx; int thread_error_stat; int thread_error_line; diff --git a/mainwindow.cpp b/mainwindow.cpp index dc32710..373eed8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -461,7 +461,8 @@ void UI_Mainwindow::close_connection() scrn_thread->wait(5000); - devparms.mutexx->unlock(); + pthread_mutex_trylock(&devparms.mutexx); + pthread_mutex_unlock(&devparms.mutexx); scrn_thread->h_busy = 0; } @@ -2714,21 +2715,21 @@ void UI_Mainwindow::screenUpdate() if(device == NULL) { - devparms.mutexx->unlock(); + pthread_mutex_unlock(&devparms.mutexx); return; } if(!devparms.connected) { - devparms.mutexx->unlock(); + pthread_mutex_unlock(&devparms.mutexx); return; } if(!devparms.screenupdates_on) { - devparms.mutexx->unlock(); + pthread_mutex_unlock(&devparms.mutexx); return; } @@ -2747,7 +2748,7 @@ void UI_Mainwindow::screenUpdate() msgBox.setText(str); msgBox.exec(); - devparms.mutexx->unlock(); + pthread_mutex_unlock(&devparms.mutexx); close_connection(); @@ -2756,7 +2757,7 @@ void UI_Mainwindow::screenUpdate() if(devparms.thread_result == TMC_THRD_RESULT_NONE) { - devparms.mutexx->unlock(); + pthread_mutex_unlock(&devparms.mutexx); return; } @@ -2770,14 +2771,14 @@ void UI_Mainwindow::screenUpdate() // waveForm->setTrigLineVisible(); } - devparms.mutexx->unlock(); + pthread_mutex_unlock(&devparms.mutexx); return; } if(scrn_timer->isActive() == false) { - devparms.mutexx->unlock(); + pthread_mutex_unlock(&devparms.mutexx); return; } @@ -2828,7 +2829,7 @@ void UI_Mainwindow::screenUpdate() if(waveForm->hasMoveEvent() == true) { - devparms.mutexx->unlock(); + pthread_mutex_unlock(&devparms.mutexx); return; } @@ -2847,7 +2848,7 @@ void UI_Mainwindow::screenUpdate() { waveForm->clear(); - devparms.mutexx->unlock(); + pthread_mutex_unlock(&devparms.mutexx); return; } @@ -2867,7 +2868,7 @@ void UI_Mainwindow::screenUpdate() waveForm->update(); } - devparms.mutexx->unlock(); + pthread_mutex_unlock(&devparms.mutexx); } diff --git a/mainwindow.h b/mainwindow.h index fa2bdf3..a129623 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -74,6 +74,7 @@ #include #include #include +#include #include "global.h" #include "about_dialog.h" diff --git a/mainwindow_constr.cpp b/mainwindow_constr.cpp index a2b834b..c541fa0 100644 --- a/mainwindow_constr.cpp +++ b/mainwindow_constr.cpp @@ -158,7 +158,7 @@ UI_Mainwindow::UI_Mainwindow() strcpy(devparms.modelname, "-----"); - devparms.mutexx = new QMutex(); + pthread_mutex_init(&devparms.mutexx, NULL); scrn_thread = new screen_thread; scrn_thread->set_device(NULL); @@ -632,7 +632,7 @@ UI_Mainwindow::~UI_Mainwindow() delete scrn_thread; delete appfont; delete monofont; - delete devparms.mutexx; + pthread_mutex_destroy(&devparms.mutexx); free(devparms.screenshot_buf); diff --git a/timer_handlers.cpp b/timer_handlers.cpp index 213a5f0..18041c8 100644 --- a/timer_handlers.cpp +++ b/timer_handlers.cpp @@ -117,7 +117,7 @@ void UI_Mainwindow::adjdial_timer_handler() void UI_Mainwindow::scrn_timer_handler() { - if(devparms.mutexx->tryLock() == false) + if(pthread_mutex_trylock(&devparms.mutexx)) { return; }