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/db_ubx.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'host/lib/usrp/dboard/db_ubx.cpp') diff --git a/host/lib/usrp/dboard/db_ubx.cpp b/host/lib/usrp/dboard/db_ubx.cpp index d36347b86..56d73bdab 100644 --- a/host/lib/usrp/dboard/db_ubx.cpp +++ b/host/lib/usrp/dboard/db_ubx.cpp @@ -21,12 +21,12 @@ #include #include #include -#include -#include +#include #include #include #include #include +#include #include using namespace uhd; @@ -595,14 +595,14 @@ private: **********************************************************************/ void write_spi_reg(spi_dest_t dest, uint32_t value) { - boost::mutex::scoped_lock lock(_spi_mutex); + std::lock_guard lock(_spi_mutex); ROUTE_SPI(_iface, dest); WRITE_SPI(_iface, value); } void write_spi_regs(spi_dest_t dest, std::vector values) { - boost::mutex::scoped_lock lock(_spi_mutex); + std::lock_guard lock(_spi_mutex); ROUTE_SPI(_iface, dest); for (uint32_t value : values) WRITE_SPI(_iface, value); @@ -759,7 +759,7 @@ private: **********************************************************************/ sensor_value_t get_locked(const std::string& pll_name) { - boost::mutex::scoped_lock lock(_mutex); + std::lock_guard lock(_mutex); assert_has(ubx_plls, pll_name, "ubx pll name"); if (pll_name == "TXLO") { @@ -785,7 +785,7 @@ private: // Set RX antennas std::string set_rx_ant(const std::string& ant) { - boost::mutex::scoped_lock lock(_mutex); + std::lock_guard lock(_mutex); // validate input assert_has(ubx_rx_antennas, ant, "ubx rx antenna name"); @@ -819,7 +819,7 @@ private: **********************************************************************/ double set_tx_gain(double gain) { - boost::mutex::scoped_lock lock(_mutex); + std::lock_guard lock(_mutex); gain = ubx_tx_gain_range.clip(gain); int attn_code = int(std::floor(gain * 2)); _ubx_tx_atten_val = ((attn_code & 0x3F) << 10); @@ -834,7 +834,7 @@ private: double set_rx_gain(double gain) { - boost::mutex::scoped_lock lock(_mutex); + std::lock_guard lock(_mutex); gain = ubx_rx_gain_range.clip(gain); int attn_code = int(std::floor(gain * 2)); _ubx_rx_atten_val = ((attn_code & 0x3F) << 10); @@ -852,7 +852,7 @@ private: **********************************************************************/ double set_tx_freq(double freq) { - boost::mutex::scoped_lock lock(_mutex); + std::lock_guard lock(_mutex); double freq_lo1 = 0.0; double freq_lo2 = 0.0; double ref_freq = _iface->get_clock_rate(dboard_iface::UNIT_TX); @@ -1000,7 +1000,7 @@ private: double set_rx_freq(double freq) { - boost::mutex::scoped_lock lock(_mutex); + std::lock_guard lock(_mutex); double freq_lo1 = 0.0; double freq_lo2 = 0.0; double ref_freq = _iface->get_clock_rate(dboard_iface::UNIT_RX); @@ -1186,7 +1186,7 @@ private: **********************************************************************/ void set_power_mode(std::string mode) { - boost::mutex::scoped_lock lock(_mutex); + std::lock_guard lock(_mutex); if (mode == "performance") { // performance mode attempts to reduce tuning and settling time // as much as possible without adding noise. @@ -1292,7 +1292,7 @@ private: } }(); - boost::mutex::scoped_lock lock(_mutex); + std::lock_guard lock(_mutex); for (const auto& lo : {_txlo1, _txlo2, _rxlo1, _rxlo2}) { lo->set_auto_retune(enabled); } @@ -1302,8 +1302,8 @@ private: * Variables **********************************************************************/ dboard_iface::sptr _iface; - boost::mutex _spi_mutex; - boost::mutex _mutex; + std::mutex _spi_mutex; + std::mutex _mutex; ubx_cpld_reg_t _cpld_reg; uint32_t _prev_cpld_value; std::map _gpio_map; -- cgit v1.2.3