]> sigrok.org Git - pulseview.git/commitdiff
Replaced boost::thread/mutex etc. with std equivalents
authorJoel Holdsworth <redacted>
Tue, 20 May 2014 22:51:00 +0000 (23:51 +0100)
committerJoel Holdsworth <redacted>
Sat, 24 May 2014 08:10:08 +0000 (09:10 +0100)
15 files changed:
CMakeLists.txt
pv/data/analog.cpp
pv/data/analogsnapshot.cpp
pv/data/decoderstack.cpp
pv/data/decoderstack.h
pv/data/logic.cpp
pv/data/logicsnapshot.cpp
pv/data/snapshot.cpp
pv/data/snapshot.h
pv/dialogs/storeprogress.cpp
pv/sigsession.cpp
pv/sigsession.h
pv/storesession.cpp
pv/storesession.h
pv/view/analogsignal.cpp

index 61daa1885b61d5bfd0035e6e876a051a373b9eab..5c66e4e6bb2bc6fb5fc17489e1f8696291229226 100644 (file)
@@ -43,10 +43,6 @@ if(WIN32)
        # This option is user configurable, but enable it by default on win32.
        set(STATIC_PKGDEPS_LIBS TRUE)
 
-       # For boost-thread we need two additional settings on win32:
-       set(Boost_USE_STATIC_LIBS ON)
-       add_definitions(-DBOOST_THREAD_USE_LIB)
-
        # Windows does not support UNIX signals.
        set(ENABLE_SIGNALS FALSE)
 endif()
@@ -73,17 +69,7 @@ pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
 find_program(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 qmake-mac)
 find_package(Qt4 REQUIRED)
 
-# Find the platform's thread library (needed for boost-thread).
-# This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
-find_package(Threads)
-
-if(WIN32)
-       # On Windows/MinGW we need to use 'thread_win32' instead of 'thread'.
-       # The library is named libboost_thread_win32* (not libboost_thread*).
-       find_package(Boost 1.42 COMPONENTS filesystem system thread_win32 REQUIRED)
-else()
-       find_package(Boost 1.42 COMPONENTS filesystem system thread REQUIRED)
-endif()
+find_package(Boost 1.42 COMPONENTS filesystem system REQUIRED)
 
 #===============================================================================
 #= System Introspection
@@ -294,7 +280,6 @@ link_directories(${Boost_LIBRARY_DIRS})
 
 set(PULSEVIEW_LINK_LIBS
        ${Boost_LIBRARIES}
-       ${CMAKE_THREAD_LIBS_INIT}
        ${QT_LIBRARIES}
 )
 
index 53fa9a5a62b117c5a1258cdc09dd05d1fc1cf446..78fd70e8750de70465160ba863bed89529cd6388 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <cassert>
+
 #include "analog.h"
 #include "analogsnapshot.h"
 
index ab968cf7362332667e2402b2cf8f59338c1a621c..9e9b5a0ffeb8bb3ce0c8b6adb3e5289b9213c4d6 100644 (file)
@@ -29,8 +29,8 @@
 
 #include "analogsnapshot.h"
 
-using boost::lock_guard;
-using boost::recursive_mutex;
+using std::lock_guard;
+using std::recursive_mutex;
 using std::max;
 using std::max_element;
 using std::min;
index 40683758a4c1280de4815e7439e09e68fc5e47cf..31dc8b309221c4721a01e3d881255955cf2ff7e5 100644 (file)
@@ -20,8 +20,6 @@
 
 #include <libsigrokdecode/libsigrokdecode.h>
 
-#include <boost/thread/thread.hpp>
-
 #include <stdexcept>
 
 #include <QDebug>
 #include <pv/sigsession.h>
 #include <pv/view/logicsignal.h>
 
-using boost::lock_guard;
-using boost::mutex;
+using std::lock_guard;
+using std::mutex;
 using boost::optional;
-using boost::unique_lock;
+using std::unique_lock;
 using std::deque;
 using std::make_pair;
 using std::max;
@@ -82,7 +80,7 @@ DecoderStack::DecoderStack(pv::SigSession &session,
 DecoderStack::~DecoderStack()
 {
        if (_decode_thread.joinable()) {
-               _decode_thread.interrupt();
+               _interrupt = true;
                _decode_thread.join();
        }
 }
@@ -186,7 +184,7 @@ void DecoderStack::begin_decode()
        shared_ptr<pv::data::Logic> data;
 
        if (_decode_thread.joinable()) {
-               _decode_thread.interrupt();
+               _interrupt = true;
                _decode_thread.join();
        }
 
@@ -256,7 +254,8 @@ void DecoderStack::begin_decode()
        if (_samplerate == 0.0)
                _samplerate = 1.0;
 
-       _decode_thread = boost::thread(&DecoderStack::decode_proc, this);
+       _interrupt = false;
+       _decode_thread = std::thread(&DecoderStack::decode_proc, this);
 }
 
 uint64_t DecoderStack::get_max_sample_count() const
@@ -273,11 +272,10 @@ uint64_t DecoderStack::get_max_sample_count() const
 optional<int64_t> DecoderStack::wait_for_data() const
 {
        unique_lock<mutex> input_lock(_input_mutex);
-       while(!boost::this_thread::interruption_requested() &&
-               !_frame_complete && _samples_decoded >= _sample_count)
+       while(!_interrupt && !_frame_complete &&
+               _samples_decoded >= _sample_count)
                _input_cond.wait(input_lock);
-       return boost::make_optional(
-               !boost::this_thread::interruption_requested() &&
+       return boost::make_optional(!_interrupt &&
                (_samples_decoded < _sample_count || !_frame_complete),
                _sample_count);
 }
@@ -291,9 +289,7 @@ void DecoderStack::decode_data(
        const unsigned int chunk_sample_count =
                DecodeChunkLength / _snapshot->unit_size();
 
-       for (int64_t i = 0;
-               !boost::this_thread::interruption_requested() &&
-                       i < sample_count;
+       for (int64_t i = 0; !_interrupt && i < sample_count;
                i += chunk_sample_count)
        {
                lock_guard<mutex> decode_lock(_global_decode_mutex);
index 1badc6b9b34988aafb41265b54d9b5681be64852..ab700ae0404bfd85129f761ed3886f413c03100b 100644 (file)
 
 #include "signaldata.h"
 
+#include <atomic>
+#include <condition_variable>
 #include <list>
+#include <map>
 #include <memory>
+#include <thread>
 
 #include <boost/optional.hpp>
-#include <boost/thread.hpp>
 
 #include <QObject>
 #include <QString>
@@ -134,18 +137,18 @@ private:
         * @todo A proper solution should be implemented to allow multiple
         * decode operations.
         */
-       static boost::mutex _global_decode_mutex;
+       static std::mutex _global_decode_mutex;
 
        std::list< std::shared_ptr<decode::Decoder> > _stack;
 
        std::shared_ptr<pv::data::LogicSnapshot> _snapshot;
 
-       mutable boost::mutex _input_mutex;
-       mutable boost::condition_variable _input_cond;
+       mutable std::mutex _input_mutex;
+       mutable std::condition_variable _input_cond;
        int64_t _sample_count;
        bool _frame_complete;
 
-       mutable boost::mutex _output_mutex;
+       mutable std::mutex _output_mutex;
        int64_t _samples_decoded;
 
        std::map<const decode::Row, decode::RowData> _rows;
@@ -154,7 +157,8 @@ private:
 
        QString _error_message;
 
-       boost::thread _decode_thread;
+       std::thread _decode_thread;
+       std::atomic<bool> _interrupt;
 
        friend class DecoderStackTest::TwoDecoderStack;
 };
index 2737bcb58238870b63066231778ca674c6231e25..6addea3b10a4440ec84357dd2d3fe47bc5ff1590 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <cassert>
+
 #include "logic.h"
 #include "logicsnapshot.h"
 
index f896ed178718dd2dc6f840c6567dcba15c4220e2..3bd43c9208182e92bed8d46b8bea108d1e1af4c5 100644 (file)
@@ -28,8 +28,8 @@
 #include "config.h"
 #include "logicsnapshot.h"
 
-using boost::lock_guard;
-using boost::recursive_mutex;
+using std::lock_guard;
+using std::recursive_mutex;
 using std::max;
 using std::min;
 using std::pair;
index 6ba39d2fe9ef57b32f8e67747ccdc65d25dbf170..2f3f041346b3a96709b21d529c7f5cd2747b7b48 100644 (file)
@@ -24,8 +24,8 @@
 #include <stdlib.h>
 #include <string.h>
 
-using boost::lock_guard;
-using boost::recursive_mutex;
+using std::lock_guard;
+using std::recursive_mutex;
 
 namespace pv {
 namespace data {
index 1f1ca3cf0b8539e7387c5211434123ce98ee42f4..499164400014d20001ae1e130c177bfcefe990be 100644 (file)
@@ -23,7 +23,8 @@
 
 #include <libsigrok/libsigrok.h>
 
-#include <boost/thread.hpp>
+#include <thread>
+#include <mutex>
 
 namespace pv {
 namespace data {
@@ -70,7 +71,7 @@ protected:
        void append_data(void *data, uint64_t samples);
 
 protected:
-       mutable boost::recursive_mutex _mutex;
+       mutable std::recursive_mutex _mutex;
        void *_data;
        uint64_t _sample_count;
        uint64_t _capacity;
index 7853173f7d0507e7af029ff609391fa5a6b8206d..bbb3881f5810c0907f2ce3efbb33148457e16a57 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include "storeprogress.h"
+#include <cassert>
 
 #include <QMessageBox>
 
+#include "storeprogress.h"
+
 namespace pv {
 namespace dialogs {
 
index 1d13de2a7fad3f786cb7f0e8dce8e30c86138f4f..84e1d48fdf19b0f62747745e0d60215d8330c066 100644 (file)
@@ -39,8 +39,8 @@
 #include "view/decodetrace.h"
 #include "view/logicsignal.h"
 
-#include <assert.h>
-
+#include <cassert>
+#include <mutex>
 #include <stdexcept>
 
 #include <sys/stat.h>
@@ -48,9 +48,9 @@
 #include <QDebug>
 
 using boost::function;
-using boost::lock_guard;
-using boost::mutex;
 using std::dynamic_pointer_cast;
+using std::lock_guard;
+using std::mutex;
 using std::list;
 using std::map;
 using std::set;
@@ -188,7 +188,7 @@ void SigSession::start_capture(function<void (const QString)> error_handler)
        }
 
        // Begin the session
-       _sampling_thread = boost::thread(
+       _sampling_thread = std::thread(
                &SigSession::sample_thread_proc, this, _dev_inst,
                        error_handler);
 }
index c7a81bfcd662de309ff9fa7dbbe65bec75fafafa..10d1e23de55d618d9a44ea36085955d23b55b3e7 100644 (file)
 #define PULSEVIEW_PV_SIGSESSION_H
 
 #include <boost/function.hpp>
-#include <boost/thread.hpp>
 
 #include <map>
 #include <memory>
+#include <mutex>
 #include <set>
 #include <string>
+#include <thread>
 #include <vector>
 
 #include <QObject>
@@ -167,19 +168,19 @@ private:
 
        std::vector< std::shared_ptr<view::DecodeTrace> > _decode_traces;
 
-       mutable boost::mutex _sampling_mutex;
+       mutable std::mutex _sampling_mutex;
        capture_state _capture_state;
 
-       mutable boost::mutex _signals_mutex;
+       mutable std::mutex _signals_mutex;
        std::vector< std::shared_ptr<view::Signal> > _signals;
 
-       mutable boost::mutex _data_mutex;
+       mutable std::mutex _data_mutex;
        std::shared_ptr<data::Logic> _logic_data;
        std::shared_ptr<data::LogicSnapshot> _cur_logic_snapshot;
        std::map< const sr_channel*, std::shared_ptr<data::AnalogSnapshot> >
                _cur_analog_snapshots;
 
-       boost::thread _sampling_thread;
+       std::thread _sampling_thread;
 
 signals:
        void capture_state_changed(int state);
index f60cd26cc621ec9225e16ef57ed37ad2113e80d9..fcba344e9fa8470b6372119eb26e552f83d312ae 100644 (file)
 #include <pv/data/logicsnapshot.h>
 #include <pv/view/signal.h>
 
-using boost::mutex;
-using boost::thread;
-using boost::lock_guard;
 using std::deque;
 using std::dynamic_pointer_cast;
+using std::lock_guard;
 using std::make_pair;
 using std::min;
+using std::mutex;
 using std::pair;
 using std::set;
 using std::shared_ptr;
 using std::string;
+using std::thread;
 using std::vector;
 
 namespace pv {
@@ -46,6 +46,7 @@ StoreSession::StoreSession(const std::string &file_name,
        const SigSession &session) :
        _file_name(file_name),
        _session(session),
+       _interrupt(false),
        _units_stored(0),
        _unit_count(0)
 {
@@ -129,7 +130,7 @@ bool StoreSession::start()
                free(probes[i]);
        delete[] probes;
 
-       _thread = boost::thread(&StoreSession::store_proc, this, snapshot);
+       _thread = std::thread(&StoreSession::store_proc, this, snapshot);
        return true;
 }
 
@@ -141,7 +142,7 @@ void StoreSession::wait()
 
 void StoreSession::cancel()
 {
-       _thread.interrupt();
+       _interrupt = true;
 }
 
 void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
@@ -164,8 +165,7 @@ void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
 
        const unsigned int samples_per_block = BlockSize / unit_size;
 
-       while (!boost::this_thread::interruption_requested() &&
-               start_sample < _unit_count)
+       while (!_interrupt && start_sample < _unit_count)
        {
                progress_updated();
 
index e543df13051eae592a8617a36e93e79f9b2763bc..4c9eae0160d7588a3543062528610d775dea0d3c 100644 (file)
 
 #include <stdint.h>
 
+#include <atomic>
+#include <mutex>
 #include <string>
-
-#include <boost/thread.hpp>
+#include <thread>
 
 #include <QObject>
 
@@ -70,9 +71,11 @@ private:
        const std::string _file_name;
        const SigSession &_session;
 
-       boost::thread _thread;
+       std::thread _thread;
+
+       std::atomic<bool> _interrupt;
 
-       mutable boost::mutex _mutex;
+       mutable std::mutex _mutex;
        uint64_t _units_stored;
        uint64_t _unit_count;
        QString _error;
index 156af1003a4440ed527516123f22352aa9768029..82e31a842c0134bfed1c94dafdb1c2c3b06129f9 100644 (file)
@@ -20,7 +20,8 @@
 
 #include <extdef.h>
 
-#include <math.h>
+#include <cassert>
+#include <cmath>
 
 #include "analogsignal.h"
 #include "pv/data/analog.h"