]> sigrok.org Git - pulseview.git/commitdiff
Get sample rate from device instance rather than storing it
authorJoel Holdsworth <redacted>
Mon, 28 Jan 2013 20:35:24 +0000 (20:35 +0000)
committerJoel Holdsworth <redacted>
Mon, 28 Jan 2013 20:36:00 +0000 (20:36 +0000)
pv/sigsession.cpp
pv/sigsession.h

index 5b9630631a1fe9c1e104e9f8437745c49d2c61ba..afe6f955a1e1e51c6aed5990e5d4dc5009220146 100644 (file)
@@ -76,12 +76,9 @@ void SigSession::start_capture(struct sr_dev_inst *sdi,
 {
        stop_capture();
 
-       lock_guard<mutex> lock(_sampling_mutex);
-       _sample_rate = sample_rate;
-
        _sampling_thread.reset(new boost::thread(
                &SigSession::sample_thread_proc, this, sdi,
-               record_length));
+               record_length, sample_rate));
 }
 
 void SigSession::stop_capture()
@@ -138,7 +135,7 @@ void SigSession::load_thread_proc(const string name)
 }
 
 void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
-       uint64_t record_length)
+       uint64_t record_length, uint64_t sample_rate)
 {
        assert(sdi);
 
@@ -160,14 +157,11 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
        }
 
        // Set the samplerate
-       {
-               lock_guard<mutex> lock(_sampling_mutex);
-               if (sr_config_set(sdi, SR_CONF_SAMPLERATE,
-                       &_sample_rate) != SR_OK) {
-                       qDebug() << "Failed to configure samplerate.";
-                       sr_session_destroy();
-                       return;
-               }
+       if (sr_config_set(sdi, SR_CONF_SAMPLERATE,
+               &sample_rate) != SR_OK) {
+               qDebug() << "Failed to configure samplerate.";
+               sr_session_destroy();
+               return;
        }
 
        if (sr_session_start() != SR_OK) {
@@ -186,6 +180,7 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
 void SigSession::feed_in_header(const sr_dev_inst *sdi)
 {
        shared_ptr<view::Signal> signal;
+       uint64_t *sample_rate;
        unsigned int logic_probe_count = 0;
        unsigned int analog_probe_count = 0;
 
@@ -206,19 +201,23 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi)
                }
        }
 
+       // Read out the sample rate
+       assert(sdi->driver);
+       assert(sr_config_get(sdi->driver, SR_CONF_SAMPLERATE,
+               (const void**)&sample_rate, sdi) == SR_OK);
+
        // Create data containers for the coming data snapshots
        {
                lock_guard<mutex> data_lock(_data_mutex);
-               lock_guard<mutex> sampling_lock(_sampling_mutex);
 
                if (logic_probe_count != 0) {
                        _logic_data.reset(new data::Logic(
-                               logic_probe_count, _sample_rate));
+                               logic_probe_count, *sample_rate));
                        assert(_logic_data);
                }
 
                if (analog_probe_count != 0) {
-                       _analog_data.reset(new data::Analog(_sample_rate));
+                       _analog_data.reset(new data::Analog(*sample_rate));
                        assert(_analog_data);
                }
        }
index 5bdd23456cfbdf88e7044d638ef434897efe2557..b8647db808f3ea7ea11f24456f22a6c196e98160 100644 (file)
@@ -83,7 +83,7 @@ private:
        void load_thread_proc(const std::string name);
 
        void sample_thread_proc(struct sr_dev_inst *sdi,
-               uint64_t record_length);
+               uint64_t record_length, uint64_t sample_rate);
 
        void feed_in_header(const sr_dev_inst *sdi);
 
@@ -103,7 +103,6 @@ private:
 private:
        mutable boost::mutex _sampling_mutex;
        capture_state _capture_state;
-       uint64_t _sample_rate;
 
        mutable boost::mutex _signals_mutex;
        std::vector< boost::shared_ptr<view::Signal> > _signals;