From: Joel Holdsworth Date: Tue, 20 May 2014 22:51:00 +0000 (+0100) Subject: Replaced boost::thread/mutex etc. with std equivalents X-Git-Tag: pulseview-0.3.0~611 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3b68d03ddae96edb38a80f31bf6a990bde21cd1d;p=pulseview.git Replaced boost::thread/mutex etc. with std equivalents --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 61daa188..5c66e4e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} ) diff --git a/pv/data/analog.cpp b/pv/data/analog.cpp index 53fa9a5a..78fd70e8 100644 --- a/pv/data/analog.cpp +++ b/pv/data/analog.cpp @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "analog.h" #include "analogsnapshot.h" diff --git a/pv/data/analogsnapshot.cpp b/pv/data/analogsnapshot.cpp index ab968cf7..9e9b5a0f 100644 --- a/pv/data/analogsnapshot.cpp +++ b/pv/data/analogsnapshot.cpp @@ -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; diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 40683758..31dc8b30 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -20,8 +20,6 @@ #include -#include - #include #include @@ -35,10 +33,10 @@ #include #include -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 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 DecoderStack::wait_for_data() const { unique_lock 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 decode_lock(_global_decode_mutex); diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index 1badc6b9..ab700ae0 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -23,11 +23,14 @@ #include "signaldata.h" +#include +#include #include +#include #include +#include #include -#include #include #include @@ -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 > _stack; std::shared_ptr _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 _rows; @@ -154,7 +157,8 @@ private: QString _error_message; - boost::thread _decode_thread; + std::thread _decode_thread; + std::atomic _interrupt; friend class DecoderStackTest::TwoDecoderStack; }; diff --git a/pv/data/logic.cpp b/pv/data/logic.cpp index 2737bcb5..6addea3b 100644 --- a/pv/data/logic.cpp +++ b/pv/data/logic.cpp @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "logic.h" #include "logicsnapshot.h" diff --git a/pv/data/logicsnapshot.cpp b/pv/data/logicsnapshot.cpp index f896ed17..3bd43c92 100644 --- a/pv/data/logicsnapshot.cpp +++ b/pv/data/logicsnapshot.cpp @@ -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; diff --git a/pv/data/snapshot.cpp b/pv/data/snapshot.cpp index 6ba39d2f..2f3f0413 100644 --- a/pv/data/snapshot.cpp +++ b/pv/data/snapshot.cpp @@ -24,8 +24,8 @@ #include #include -using boost::lock_guard; -using boost::recursive_mutex; +using std::lock_guard; +using std::recursive_mutex; namespace pv { namespace data { diff --git a/pv/data/snapshot.h b/pv/data/snapshot.h index 1f1ca3cf..49916440 100644 --- a/pv/data/snapshot.h +++ b/pv/data/snapshot.h @@ -23,7 +23,8 @@ #include -#include +#include +#include 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; diff --git a/pv/dialogs/storeprogress.cpp b/pv/dialogs/storeprogress.cpp index 7853173f..bbb3881f 100644 --- a/pv/dialogs/storeprogress.cpp +++ b/pv/dialogs/storeprogress.cpp @@ -18,10 +18,12 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "storeprogress.h" +#include #include +#include "storeprogress.h" + namespace pv { namespace dialogs { diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 1d13de2a..84e1d48f 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -39,8 +39,8 @@ #include "view/decodetrace.h" #include "view/logicsignal.h" -#include - +#include +#include #include #include @@ -48,9 +48,9 @@ #include 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 error_handler) } // Begin the session - _sampling_thread = boost::thread( + _sampling_thread = std::thread( &SigSession::sample_thread_proc, this, _dev_inst, error_handler); } diff --git a/pv/sigsession.h b/pv/sigsession.h index c7a81bfc..10d1e23d 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -22,12 +22,13 @@ #define PULSEVIEW_PV_SIGSESSION_H #include -#include #include #include +#include #include #include +#include #include #include @@ -167,19 +168,19 @@ private: std::vector< std::shared_ptr > _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 > _signals; - mutable boost::mutex _data_mutex; + mutable std::mutex _data_mutex; std::shared_ptr _logic_data; std::shared_ptr _cur_logic_snapshot; std::map< const sr_channel*, std::shared_ptr > _cur_analog_snapshots; - boost::thread _sampling_thread; + std::thread _sampling_thread; signals: void capture_state_changed(int state); diff --git a/pv/storesession.cpp b/pv/storesession.cpp index f60cd26c..fcba344e 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -25,17 +25,17 @@ #include #include -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 snapshot) @@ -164,8 +165,7 @@ void StoreSession::store_proc(shared_ptr 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(); diff --git a/pv/storesession.h b/pv/storesession.h index e543df13..4c9eae01 100644 --- a/pv/storesession.h +++ b/pv/storesession.h @@ -23,9 +23,10 @@ #include +#include +#include #include - -#include +#include #include @@ -70,9 +71,11 @@ private: const std::string _file_name; const SigSession &_session; - boost::thread _thread; + std::thread _thread; + + std::atomic _interrupt; - mutable boost::mutex _mutex; + mutable std::mutex _mutex; uint64_t _units_stored; uint64_t _unit_count; QString _error; diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 156af100..82e31a84 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -20,7 +20,8 @@ #include -#include +#include +#include #include "analogsignal.h" #include "pv/data/analog.h"