From f6ca1f6ed8e8e1b3e6edb7dcb335444020c51227 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Thu, 25 Nov 2021 15:41:00 +0800 Subject: [PATCH] fix capture thread stop bug --- DSView/pv/data/snapshot.cpp | 42 +---------- DSView/pv/data/snapshot.h | 36 ++++++--- DSView/pv/device/devinst.cpp | 7 +- DSView/pv/mainwindow.cpp | 11 ++- DSView/pv/mainwindow.h | 4 +- libsigrok4DSL/libsigrok-internal.h | 2 +- libsigrok4DSL/session.c | 16 ++-- libsigrokdecode4DSL/config.h | 114 +++++++++++++++++++++++++++++ 8 files changed, 161 insertions(+), 71 deletions(-) create mode 100644 libsigrokdecode4DSL/config.h diff --git a/DSView/pv/data/snapshot.cpp b/DSView/pv/data/snapshot.cpp index bac3cc16..c359addb 100755 --- a/DSView/pv/data/snapshot.cpp +++ b/DSView/pv/data/snapshot.cpp @@ -64,11 +64,6 @@ void Snapshot::free_data() _ch_index.clear(); } -bool Snapshot::memory_failed() -{ - return _memory_failed; -} - bool Snapshot::empty() { if (get_sample_count() == 0) @@ -77,16 +72,6 @@ bool Snapshot::empty() return false; } -bool Snapshot::last_ended() -{ - return _last_ended; -} - -void Snapshot::set_last_ended(bool ended) -{ - _last_ended = ended; -} - uint64_t Snapshot::get_sample_count() { std::lock_guard lock(_mutex); @@ -104,12 +89,7 @@ uint64_t Snapshot::get_ring_end() std::lock_guard lock(_mutex); return ring_end(); } - -uint64_t Snapshot::sample_count() -{ - return _sample_count; -} - + uint64_t Snapshot::ring_start() { if (_sample_count < _total_sample_count) @@ -128,26 +108,6 @@ uint64_t Snapshot::ring_end() return _ring_sample_count - 1; } -const void* Snapshot::get_data() -{ - return _data; -} - -int Snapshot::unit_size() -{ - return _unit_size; -} - -uint8_t Snapshot::get_unit_bytes() -{ - return _unit_bytes; -} - -unsigned int Snapshot::get_channel_num() -{ - return _channel_num; -} - void Snapshot::capture_ended() { set_last_ended(true); diff --git a/DSView/pv/data/snapshot.h b/DSView/pv/data/snapshot.h index b3447b89..5113aef0 100755 --- a/DSView/pv/data/snapshot.h +++ b/DSView/pv/data/snapshot.h @@ -43,18 +43,35 @@ public: uint64_t get_ring_start(); uint64_t get_ring_end(); - const void * get_data(); + inline const void* get_data(){ + return _data; + } - int unit_size(); - uint8_t get_unit_bytes(); + inline int unit_size(){ + return _unit_size; + } + + inline uint8_t get_unit_bytes(){ + return _unit_bytes; + } + + inline bool memory_failed(){ + return _memory_failed; + } - bool memory_failed(); bool empty(); - bool last_ended(); - void set_last_ended(bool ended); + inline bool last_ended(){ + return _last_ended; + } - unsigned int get_channel_num(); + inline void set_last_ended(bool ended){ + _last_ended = ended; + } + + inline unsigned int get_channel_num(){ + return _channel_num; + } virtual void capture_ended(); virtual bool has_data(int index) = 0; @@ -64,10 +81,11 @@ public: protected: virtual void free_data(); - uint64_t sample_count(); + inline uint64_t sample_count(){ + return _sample_count; + } uint64_t ring_start(); - uint64_t ring_end(); protected: diff --git a/DSView/pv/device/devinst.cpp b/DSView/pv/device/devinst.cpp index 29777872..f4b03485 100755 --- a/DSView/pv/device/devinst.cpp +++ b/DSView/pv/device/devinst.cpp @@ -200,7 +200,12 @@ void DevInst::start() void DevInst::run() { - sr_session_run(); + qDebug()<<"session run loop start"; + int ret = sr_session_run(); + if (ret != SR_OK){ + qDebug()<<"start session error!"; + } + qDebug()<<"session run loop end"; } void DevInst::stop() diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 61979413..cbd65ecd 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include @@ -236,10 +237,7 @@ void MainWindow::setup_ui() // UI initial _measure_widget->add_dist_measure(); - - // update device - update_device_list(); - + _session->start_hotplug_work(); retranslateUi(); @@ -302,6 +300,9 @@ void MainWindow::setup_ui() connect(_dso_trigger_widget, SIGNAL(set_trig_pos(int)), _view, SLOT(set_trig_pos(int))); _logo_bar->set_mainform_callback(this); + + //delay to update device list + QTimer::singleShot(200, this, SLOT(update_device_list())); } @@ -457,8 +458,6 @@ void MainWindow::on_load_file(QString file_name) } catch(QString e) { show_error(tr("Failed to load ") + file_name); _session->set_default_device(); - update_device_list(); - return; } update_device_list(); diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index 8cbf35a9..6e284bb8 100755 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -91,8 +91,7 @@ private: void setup_ui(); void retranslateUi(); bool eventFilter(QObject *object, QEvent *event); - bool load_session_json(QJsonDocument json, bool file_dev,bool bDecoder=true); - void update_device_list(); + bool load_session_json(QJsonDocument json, bool file_dev,bool bDecoder=true); public slots: void switchTheme(QString style); @@ -102,6 +101,7 @@ private slots: void on_load_file(QString file_name); void on_open_doc(); void on_device_updated_reload(); + void update_device_list(); void on_run_stop(); void on_instant_stop(); diff --git a/libsigrok4DSL/libsigrok-internal.h b/libsigrok4DSL/libsigrok-internal.h index 9eb3f5fc..c310a370 100755 --- a/libsigrok4DSL/libsigrok-internal.h +++ b/libsigrok4DSL/libsigrok-internal.h @@ -28,7 +28,7 @@ #endif // firmware binary file directory, endswith letter '/' -extern char DS_RES_PATH[256]; +extern char DS_RES_PATH[500]; /** * @file diff --git a/libsigrok4DSL/session.c b/libsigrok4DSL/session.c index ba857999..74ca9996 100755 --- a/libsigrok4DSL/session.c +++ b/libsigrok4DSL/session.c @@ -34,12 +34,10 @@ #define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args) #define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args) -char DS_RES_PATH[256] = {0}; +char DS_RES_PATH[500] = {0}; int bExportOriginalData = 0; //able export all data -int session_loop_stop_flag = 0; - /** * @file * @@ -407,14 +405,12 @@ SR_API int sr_session_run(void) session->running = TRUE; - session_loop_stop_flag = 0; - sr_info("Running..."); /* Do we have real sources? */ if (session->num_sources == 1 && session->pollfds[0].fd == -1) { /* Dummy source, freewheel over it. */ - while (session->num_sources && !session_loop_stop_flag) { + while (session->num_sources) { if (session->abort_session) { session->sources[0].cb(-1, -1, session->sources[0].cb_data); break; @@ -424,7 +420,7 @@ SR_API int sr_session_run(void) } } else { /* Real sources, use g_poll() main loop. */ - while (session->num_sources && !session_loop_stop_flag){ + while (session->num_sources){ sr_session_iteration(TRUE); } } @@ -491,8 +487,6 @@ SR_API int sr_session_stop(void) return SR_ERR_BUG; } - session_loop_stop_flag = 1; //set flag, the run loop will exit - g_mutex_lock(&session->stop_mutex); if (session->running) session->abort_session = TRUE; @@ -841,8 +835,8 @@ void sr_set_firmware_resource_dir(const char *dir) int len = strlen(DS_RES_PATH); if (DS_RES_PATH[len-1] != '/'){ - DS_RES_PATH[len] = '/'; - DS_RES_PATH[len+1] = 0; + DS_RES_PATH[len] = '/'; + DS_RES_PATH[len + 1] = 0; } } } diff --git a/libsigrokdecode4DSL/config.h b/libsigrokdecode4DSL/config.h new file mode 100644 index 00000000..1d480390 --- /dev/null +++ b/libsigrokdecode4DSL/config.h @@ -0,0 +1,114 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* The canonical host libsigrokdecode will run on. */ +#define CONF_HOST "x86_64-pc-linux-gnu" + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "support@dreamsourcelab.com" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libsigrokdecode4DSL" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "libsigrokdecode4DSL 0.6.0" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libsigrokdecode4DSL" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "http://www.dreamsourcelab.com" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "0.6.0" + +/* Binary age of libsigrokdecode4DSL. */ +#define SRD_LIB_VERSION_AGE 0 + +/* Binary version of libsigrokdecode4DSL. */ +#define SRD_LIB_VERSION_CURRENT 4 + +/* Binary revision of libsigrokdecode4DSL. */ +#define SRD_LIB_VERSION_REVISION 0 + +/* Binary version triple of libsigrokdecode4DSL. */ +#define SRD_LIB_VERSION_STRING "4:0:0" + +/* Major version number of libsigrokdecode4DSL. */ +#define SRD_PACKAGE_VERSION_MAJOR 0 + +/* Micro version number of libsigrokdecode4DSL. */ +#define SRD_PACKAGE_VERSION_MICRO 0 + +/* Minor version number of libsigrokdecode4DSL. */ +#define SRD_PACKAGE_VERSION_MINOR 6 + +/* Version of libsigrokdecode4DSL. */ +#define SRD_PACKAGE_VERSION_STRING "0.6.0-git-c708a00" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* The targeted POSIX standard. */ +#ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +#endif