From: Joel Holdsworth Date: Sun, 2 Dec 2012 14:32:48 +0000 (+0000) Subject: Initial threaded capture X-Git-Tag: pulseview-0.1.0~208 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=2e2946fe1bbb043d1c0c8a824bc753db0920469d;p=pulseview.git Initial threaded capture --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 812176ec..042cdae3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,14 +46,14 @@ pkg_check_modules(PKGDEPS REQUIRED libsigrok>=0.2.0 ) +find_package(Qt4 REQUIRED) + # On Windows/MinGW we explicitly point cmake to the Boost directory. if(WIN32) set(BOOST_ROOT /usr/local) endif() -find_package(Qt4 REQUIRED) - -find_package(Boost 1.46) +find_package(Boost 1.46 COMPONENTS thread) #=============================================================================== #= Config Header diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 81ccca72..137998bd 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -44,6 +44,10 @@ SigSession::SigSession() SigSession::~SigSession() { + if(_sampling_thread.get()) + _sampling_thread->join(); + _sampling_thread.reset(); + // TODO: This should not be necessary _session = NULL; } @@ -61,6 +65,28 @@ void SigSession::load_file(const std::string &name) void SigSession::start_capture(struct sr_dev_inst *sdi, uint64_t record_length, uint64_t sample_rate) +{ + // Check sampling isn't already active + if(_sampling_thread.get()) + _sampling_thread->join(); + + _sampling_thread.reset(new boost::thread( + &SigSession::sample_thread_proc, this, sdi, + record_length, sample_rate)); +} + +vector< shared_ptr >& SigSession::get_signals() +{ + return _signals; +} + +boost::shared_ptr SigSession::get_data() +{ + return _logic_data; +} + +void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, + uint64_t record_length, uint64_t sample_rate) { sr_session_new(); sr_session_datafeed_callback_add(data_feed_in_proc); @@ -94,16 +120,6 @@ void SigSession::start_capture(struct sr_dev_inst *sdi, sr_session_destroy(); } -vector< shared_ptr >& SigSession::get_signals() -{ - return _signals; -} - -boost::shared_ptr SigSession::get_data() -{ - return _logic_data; -} - void SigSession::data_feed_in(const struct sr_dev_inst *sdi, struct sr_datafeed_packet *packet) { @@ -114,43 +130,49 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, switch (packet->type) { case SR_DF_HEADER: + { + lock_guard lock(_data_mutex); _signals.clear(); break; + } case SR_DF_META_LOGIC: - { - assert(packet->payload); + { + assert(packet->payload); - const sr_datafeed_meta_logic &meta_logic = - *(sr_datafeed_meta_logic*)packet->payload; + lock_guard lock(_data_mutex); - // Create an empty LogiData for coming data snapshots - _logic_data.reset(new LogicData(meta_logic)); - assert(_logic_data); - if(!_logic_data) - break; + const sr_datafeed_meta_logic &meta_logic = + *(sr_datafeed_meta_logic*)packet->payload; - // Add the signals - for (int i = 0; i < meta_logic.num_probes; i++) + // Create an empty LogiData for coming data snapshots + _logic_data.reset(new LogicData(meta_logic)); + assert(_logic_data); + if(!_logic_data) + break; + + // Add the signals + for (int i = 0; i < meta_logic.num_probes; i++) + { + const sr_probe *const probe = + (const sr_probe*)g_slist_nth_data( + sdi->probes, i); + if(probe->enabled) { - const sr_probe *const probe = - (const sr_probe*)g_slist_nth_data( - sdi->probes, i); - if(probe->enabled) - { - shared_ptr signal( - new LogicSignal(probe->name, - _logic_data, - probe->index)); - _signals.push_back(signal); - } + shared_ptr signal( + new LogicSignal(probe->name, + _logic_data, + probe->index)); + _signals.push_back(signal); } - - break; } - case SR_DF_LOGIC: + break; + } + case SR_DF_LOGIC: + { + lock_guard lock(_data_mutex); assert(packet->payload); if(!_cur_logic_snapshot) { @@ -168,12 +190,18 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, } break; + } case SR_DF_END: - _cur_logic_snapshot.reset(); + { + { + lock_guard lock(_data_mutex); + _cur_logic_snapshot.reset(); + } data_updated(); break; } + } } void SigSession::data_feed_in_proc(const struct sr_dev_inst *sdi, diff --git a/pv/sigsession.h b/pv/sigsession.h index 29929a9d..744d8340 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -22,8 +22,10 @@ #define PULSEVIEW_PV_SIGSESSION_H #include +#include #include +#include #include #include @@ -61,6 +63,9 @@ public: boost::shared_ptr get_data(); private: + void sample_thread_proc(struct sr_dev_inst *sdi, + uint64_t record_length, uint64_t sample_rate); + void data_feed_in(const struct sr_dev_inst *sdi, struct sr_datafeed_packet *packet); @@ -68,10 +73,13 @@ private: struct sr_datafeed_packet *packet); private: + mutable boost::mutex _data_mutex; std::vector< boost::shared_ptr > _signals; boost::shared_ptr _logic_data; boost::shared_ptr _cur_logic_snapshot; + std::auto_ptr _sampling_thread; + signals: void data_updated();