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/examples/network_relay.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'host/examples') diff --git a/host/examples/network_relay.cpp b/host/examples/network_relay.cpp index 15c6de4ef..910584452 100644 --- a/host/examples/network_relay.cpp +++ b/host/examples/network_relay.cpp @@ -8,15 +8,15 @@ #include #include #include -#include #include -#include +#include #include #include #include #include #include #include +#include #include #include @@ -99,7 +99,7 @@ public: } std::cout << "spawning relay threads... " << _port << std::endl; - boost::unique_lock lock( + std::unique_lock lock( spawn_mutex); // lock in preparation to wait for threads to spawn (void)_thread_group.create_thread( std::bind(&udp_relay_type::server_thread, this)); @@ -134,7 +134,7 @@ private: std::vector buff(insane_mtu); while (not boost::this_thread::interruption_requested()) { if (wait_for_recv_ready(_server_socket->native_handle())) { - boost::mutex::scoped_lock lock(_endpoint_mutex); + std::unique_lock lock(_endpoint_mutex); const size_t len = _server_socket->receive_from( asio::buffer(&buff.front(), buff.size()), _endpoint); lock.unlock(); @@ -164,7 +164,7 @@ private: if (wait_for_recv_ready(_client_socket->native_handle())) { const size_t len = _client_socket->receive(asio::buffer(&buff.front(), buff.size())); - boost::mutex::scoped_lock lock(_endpoint_mutex); + std::lock_guard lock(_endpoint_mutex); _server_socket->send_to(asio::buffer(&buff.front(), len), _endpoint); } } @@ -175,10 +175,10 @@ private: boost::thread_group _thread_group; asio::io_service _io_service; asio::ip::udp::endpoint _endpoint; - boost::mutex _endpoint_mutex; + std::mutex _endpoint_mutex; socket_type _server_socket, _client_socket; - boost::mutex spawn_mutex; - boost::condition_variable wait_for_thread; + std::mutex spawn_mutex; + boost::condition wait_for_thread; }; @@ -206,7 +206,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) // print the help message if (vm.count("help") or not vm.count("addr")) { - std::cout << boost::format("UHD Network Relay %s") % desc << std::endl + std::cout << "UHD Network Relay " << desc << std::endl << "Runs a network relay between UHD on one computer and a USRP on the " "network.\n" << "This example is basically for test purposes. Use at your own " -- cgit v1.2.3