]> sigrok.org Git - pulseview.git/commitdiff
Fix compilation on 32-bit systems
authorMarcus Comstedt <redacted>
Sun, 29 Jun 2014 12:09:03 +0000 (14:09 +0200)
committerMarcus Comstedt <redacted>
Sun, 29 Jun 2014 12:15:35 +0000 (14:15 +0200)
storesession.h was declaring fields as std::atomic<uint64_t>, a type
not avaiable on 32-bit systems.  However, the values stored in these
fields were only used as input to QProgressDialog, which takes int,
not uint64_t.  So the fields could just as well be std::atomic<int>.

Also, added code to scale the progress values down if they would not
fit in an int.  (This would have been needed even if the fields were
to remain as uint64_t.)

pv/dialogs/storeprogress.cpp
pv/storesession.cpp
pv/storesession.h

index ecda1d0ec7c680ae1ec72f08011fa830deafa65c..5c2d8bc16cf0952a61c14736da031209475875e6 100644 (file)
@@ -66,7 +66,7 @@ void StoreProgress::closeEvent(QCloseEvent*)
 
 void StoreProgress::on_progress_updated()
 {
 
 void StoreProgress::on_progress_updated()
 {
-       const std::pair<uint64_t, uint64_t> p = _session.progress();
+       const std::pair<int, int> p = _session.progress();
        assert(p.first <= p.second);
 
        if (p.second) {
        assert(p.first <= p.second);
 
        if (p.second) {
index 5eaff586b6ff787a7fc6a9bb4308a3b2deac3132..dede6a064cb8eda309f7384e180059bdb6398fd8 100644 (file)
@@ -59,7 +59,7 @@ StoreSession::~StoreSession()
        wait();
 }
 
        wait();
 }
 
-pair<uint64_t, uint64_t> StoreSession::progress() const
+pair<int, int> StoreSession::progress() const
 {
        return make_pair(_units_stored.load(), _unit_count.load());
 }
 {
        return make_pair(_units_stored.load(), _unit_count.load());
 }
@@ -150,7 +150,8 @@ void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
 {
        assert(snapshot);
 
 {
        assert(snapshot);
 
-       uint64_t start_sample = 0;
+       uint64_t start_sample = 0, sample_count;
+       unsigned progress_scale = 0;
 
        /// TODO: Wrap this in a std::unique_ptr when we transition to C++11
        uint8_t *const data = new uint8_t[BlockSize];
 
        /// TODO: Wrap this in a std::unique_ptr when we transition to C++11
        uint8_t *const data = new uint8_t[BlockSize];
@@ -159,16 +160,23 @@ void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
        const int unit_size = snapshot->unit_size();
        assert(unit_size != 0);
 
        const int unit_size = snapshot->unit_size();
        assert(unit_size != 0);
 
-       _unit_count = snapshot->get_sample_count();
+       sample_count = snapshot->get_sample_count();
+
+       // Qt needs the progress values to fit inside an int.  If they would
+       // not, scale the current and max values down until they do.
+       while ((sample_count >> progress_scale) > INT_MAX)
+               progress_scale ++;
+
+       _unit_count = sample_count >> progress_scale;
 
        const unsigned int samples_per_block = BlockSize / unit_size;
 
 
        const unsigned int samples_per_block = BlockSize / unit_size;
 
-       while (!_interrupt && start_sample < _unit_count)
+       while (!_interrupt && start_sample < sample_count)
        {
                progress_updated();
 
                const uint64_t end_sample = min(
        {
                progress_updated();
 
                const uint64_t end_sample = min(
-                       start_sample + samples_per_block, _unit_count.load());
+                       start_sample + samples_per_block, sample_count);
                snapshot->get_samples(data, start_sample, end_sample);
 
                if(sr_session_append(_file_name.c_str(), data, unit_size,
                snapshot->get_samples(data, start_sample, end_sample);
 
                if(sr_session_append(_file_name.c_str(), data, unit_size,
@@ -179,7 +187,7 @@ void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
                }
 
                start_sample = end_sample;
                }
 
                start_sample = end_sample;
-               _units_stored = start_sample;
+               _units_stored = start_sample >> progress_scale;
        }
 
        _unit_count = 0;
        }
 
        _unit_count = 0;
index 262eddc1eff3a9ad92afef0d673aa85bcb94d5f2..ffe1facd742c9b5a194ed4bb75fc2e69f4e4b40e 100644 (file)
@@ -51,7 +51,7 @@ public:
 
        ~StoreSession();
 
 
        ~StoreSession();
 
-       std::pair<uint64_t, uint64_t> progress() const;
+       std::pair<int, int> progress() const;
 
        const QString& error() const;
 
 
        const QString& error() const;
 
@@ -75,7 +75,7 @@ private:
 
        std::atomic<bool> _interrupt;
 
 
        std::atomic<bool> _interrupt;
 
-       std::atomic<uint64_t> _units_stored, _unit_count;
+       std::atomic<int> _units_stored, _unit_count;
 
        mutable std::mutex _mutex;
        QString _error;
 
        mutable std::mutex _mutex;
        QString _error;