From b6119e581e6ea9273b188463dc4529c30db140ba Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 6 Jul 2021 16:51:55 +0200 Subject: uhd: Replace Boost mutexes and locks with standard options This is a very mechanical task that could almost have been done with sed. Boost versions of mutexes and locks were removed, and replaced with std:: versions. The replacement tables are as follows: == Mutexes == - boost::mutex -> std::mutex - boost::recursive_mutex -> std::recursive_mutex Mutexes behave identically between Boost and std:: and have the same API. == Locks == C++11 has only two types of lock that we use/need in UHD: - std::lock_guard: Identical to boost::lock_guard - std::unique_lock: Identical to boost::unique_lock Boost also has boost::mutex::scoped_lock, which is a typedef for boost::unique_lock<>. However, we often have used scoped_lock where we meant to use lock_guard<>. The name is a bit misleading, "scoped lock" sounding a bit like an RAII mechanism. Therefore, some previous boost::mutex::scoped_lock are now std::lock_guard<>. std::unique_lock is required when doing more than RAII locking (i.e., unlocking, relocking, usage with condition variables, etc.). == Condition Variables == Condition variables were out of the scope of this lock/mutex change, but in UHD, we inconsistently use boost::condition vs. boost::condition_variable. The former is a templated version of the latter, and thus works fine with std::mutex'es. Therefore, some boost::condition_variable where changed to boost::condition. All locks and mutexes use `#include `. The corresponding Boost includes were removed. In some cases, this exposed issues with implicit Boost includes elsewhere. The missing explicit includes were added. --- host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp | 52 +++++++++++++++-------------- host/lib/usrp/dboard/twinrx/twinrx_io.hpp | 10 +++--- 2 files changed, 32 insertions(+), 30 deletions(-) (limited to 'host/lib/usrp/dboard/twinrx') diff --git a/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp b/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp index 29ab194be..355d980ee 100644 --- a/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp +++ b/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -158,19 +160,19 @@ public: ~twinrx_ctrl_impl() override { - UHD_SAFE_CALL(boost::lock_guard lock(_mutex); + UHD_SAFE_CALL(std::lock_guard lock(_mutex); _gpio_iface->set_field(twinrx_gpio::FIELD_SWPS_EN, 0);) } void commit() override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); _commit(); } void set_chan_enabled(channel_t ch, bool enabled, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (ch == CH1 or ch == BOTH) { _cpld_regs->if0_reg3.set(rm::if0_reg3_t::IF1_IF2_EN_CH1, bool2bin(enabled)); _cpld_regs->if0_reg0.set(rm::if0_reg0_t::AMP_LO2_EN_CH1, bool2bin(enabled)); @@ -191,7 +193,7 @@ public: void set_preamp1(channel_t ch, preamp_state_t value, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (ch == CH1 or ch == BOTH) { _cpld_regs->rf0_reg1.set( rm::rf0_reg1_t::SWPA1_CTL_CH1, bool2bin(value == PREAMP_HIGHBAND)); @@ -218,7 +220,7 @@ public: void set_preamp2(channel_t ch, bool enabled, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (ch == CH1 or ch == BOTH) { _cpld_regs->rf2_reg7.set( rm::rf2_reg7_t::SWPA4_CTRL_CH1, bool2bin(not enabled)); @@ -236,7 +238,7 @@ public: void set_lb_preamp_preselector( channel_t ch, bool enabled, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (ch == CH1 or ch == BOTH) { _cpld_regs->rf0_reg7.set( rm::rf0_reg7_t::SWPA3_CTRL_CH1, bool2bin(not enabled)); @@ -251,7 +253,7 @@ public: void set_signal_path(channel_t ch, signal_path_t path, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (ch == CH1 or ch == BOTH) { _cpld_regs->rf2_reg2.set( rm::rf2_reg2_t::SW11_CTRL_CH1, bool2bin(path == PATH_LOWBAND)); @@ -299,7 +301,7 @@ public: void set_lb_preselector( channel_t ch, preselector_path_t path, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); uint32_t sw7val = 0, sw8val = 0; switch (path) { case PRESEL_PATH1: @@ -336,7 +338,7 @@ public: void set_hb_preselector( channel_t ch, preselector_path_t path, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); uint32_t sw9ch1val = 0, sw10ch1val = 0, sw9ch2val = 0, sw10ch2val = 0; switch (path) { case PRESEL_PATH1: @@ -380,7 +382,7 @@ public: void set_input_atten(channel_t ch, uint8_t atten, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (ch == CH1 or ch == BOTH) { _cpld_regs->rf0_reg0.set(rm::rf0_reg0_t::ATTEN_IN_CH1, atten & 0x1F); } @@ -393,7 +395,7 @@ public: void set_lb_atten(channel_t ch, uint8_t atten, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (ch == CH1 or ch == BOTH) { _cpld_regs->rf2_reg0.set(rm::rf2_reg0_t::ATTEN_LB_CH1, atten & 0x1F); } @@ -406,7 +408,7 @@ public: void set_hb_atten(channel_t ch, uint8_t atten, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (ch == CH1 or ch == BOTH) { _cpld_regs->rf1_reg0.set(rm::rf1_reg0_t::ATTEN_HB_CH1, atten & 0x1F); } @@ -419,7 +421,7 @@ public: void set_lo1_source(channel_t ch, lo_source_t source, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (ch == CH1 or ch == BOTH) { _cpld_regs->rf1_reg5.set( rm::rf1_reg5_t::SW14_CTRL_CH2, bool2bin(source != LO_COMPANION)); @@ -447,7 +449,7 @@ public: void set_lo2_source(channel_t ch, lo_source_t source, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (ch == CH1 or ch == BOTH) { _cpld_regs->if0_reg0.set( rm::if0_reg0_t::SW19_CTRL_CH2, bool2bin(source == LO_COMPANION)); @@ -472,7 +474,7 @@ public: void set_lo1_export_source(lo_export_source_t source, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); // SW22 may conflict with the cal switch but this attr takes priority and we // assume that the cal switch is disabled (by disabling it!) _set_cal_mode(CAL_DISABLED, source); @@ -486,7 +488,7 @@ public: void set_lo2_export_source(lo_export_source_t source, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); _cpld_regs->if0_reg7.set( rm::if0_reg7_t::SW24_CTRL_CH2, bool2bin(source == LO_CH2_SYNTH)); _cpld_regs->if0_reg4.set( @@ -501,7 +503,7 @@ public: void set_antenna_mapping(antenna_mapping_t mapping, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); enum switch_path_t { CONNECT, TERM, EXPORT, IMPORT, SWAP }; switch_path_t path1, path2; @@ -548,7 +550,7 @@ public: void set_crossover_cal_mode(cal_mode_t cal_mode, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); if (_lo1_export == LO_CH1_SYNTH && cal_mode == CAL_CH2) { throw uhd::runtime_error( "cannot enable cal crossover on CH2 when LO1 in CH1 is exported"); @@ -565,7 +567,7 @@ public: double set_lo1_synth_freq(channel_t ch, double freq, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); double coerced_freq = 0.0; if (ch == CH1 or ch == BOTH) { @@ -586,7 +588,7 @@ public: double set_lo2_synth_freq(channel_t ch, double freq, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); double coerced_freq = 0.0; if (ch == CH1 or ch == BOTH) { @@ -605,7 +607,7 @@ public: double set_lo1_charge_pump(channel_t ch, double current, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); double coerced_current = 0.0; if (ch == CH1 or ch == BOTH) { coerced_current = @@ -624,7 +626,7 @@ public: double set_lo2_charge_pump(channel_t ch, double current, bool commit = true) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); double coerced_current = 0.0; if (ch == CH1 or ch == BOTH) { coerced_current = @@ -655,7 +657,7 @@ public: bool read_lo1_locked(channel_t ch) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); bool locked = true; if (ch == CH1 or ch == BOTH) { @@ -671,7 +673,7 @@ public: bool read_lo2_locked(channel_t ch) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); bool locked = true; if (ch == CH1 or ch == BOTH) { @@ -851,7 +853,7 @@ private: // Members } }; - boost::mutex _mutex; + std::mutex _mutex; dboard_iface::sptr _db_iface; twinrx_gpio::sptr _gpio_iface; twinrx_cpld_regmap::sptr _cpld_regs; diff --git a/host/lib/usrp/dboard/twinrx/twinrx_io.hpp b/host/lib/usrp/dboard/twinrx/twinrx_io.hpp index 538b0bfa8..5998a87d1 100644 --- a/host/lib/usrp/dboard/twinrx/twinrx_io.hpp +++ b/host/lib/usrp/dboard/twinrx/twinrx_io.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include namespace uhd { namespace usrp { namespace dboard { namespace twinrx { @@ -95,7 +95,7 @@ public: void set_field(const uhd::soft_reg_field_t field, const uint32_t value) { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); using namespace soft_reg_field; _db_iface->set_gpio_out( @@ -104,7 +104,7 @@ public: uint32_t get_field(const uhd::soft_reg_field_t field) { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); using namespace soft_reg_field; return (_db_iface->read_gpio(dboard_iface::UNIT_BOTH) & mask(field)) >> shift(field); @@ -113,7 +113,7 @@ public: // CPLD register write-only interface void poke32(const wb_addr_type addr, const uint32_t data) override { - boost::lock_guard lock(_mutex); + std::lock_guard lock(_mutex); using namespace soft_reg_field; // Step 1: Write the reg offset and data to the GPIO bus and de-assert all enables @@ -140,7 +140,7 @@ private: // Members/definitions // Members dboard_iface::sptr _db_iface; - boost::mutex _mutex; + std::mutex _mutex; }; class twinrx_cpld_regmap : public uhd::soft_regmap_t -- cgit v1.2.3