From 9e47ad607b597954e786db6614f5b42123184ccd Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Wed, 27 Nov 2013 12:11:23 -0800 Subject: Squashed merge of Coverity fixes. --- host/examples/network_relay.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'host/examples/network_relay.cpp') diff --git a/host/examples/network_relay.cpp b/host/examples/network_relay.cpp index bb09296b3..fc1ebd91d 100644 --- a/host/examples/network_relay.cpp +++ b/host/examples/network_relay.cpp @@ -33,8 +33,6 @@ typedef boost::shared_ptr socket_type; static const size_t insane_mtu = 9000; -boost::mutex spawn_mutex; - #if defined(UHD_PLATFORM_MACOS) //limit buffer resize on macos or it will error const size_t rx_dsp_buff_size = size_t(1e6); @@ -100,14 +98,11 @@ public: } std::cout << "spawning relay threads... " << _port << std::endl; + boost::unique_lock lock(spawn_mutex); // lock in preparation to wait for threads to spawn _thread_group.create_thread(boost::bind(&udp_relay_type::server_thread, this)); - spawn_mutex.lock(); - spawn_mutex.lock(); - spawn_mutex.unlock(); + wait_for_thread.wait(lock); // wait for thread to spin up _thread_group.create_thread(boost::bind(&udp_relay_type::client_thread, this)); - spawn_mutex.lock(); - spawn_mutex.lock(); - spawn_mutex.unlock(); + wait_for_thread.wait(lock); // wait for thread to spin up std::cout << " done!" << std::endl << std::endl; } @@ -128,7 +123,7 @@ private: void server_thread(void){ uhd::set_thread_priority_safe(); std::cout << " entering server_thread..." << std::endl; - spawn_mutex.unlock(); + wait_for_thread.notify_one(); // notify constructor that this thread has started std::vector buff(insane_mtu); while (not boost::this_thread::interruption_requested()){ if (wait_for_recv_ready(_server_socket->native())){ @@ -154,7 +149,7 @@ private: void client_thread(void){ uhd::set_thread_priority_safe(); std::cout << " entering client_thread..." << std::endl; - spawn_mutex.unlock(); + wait_for_thread.notify_one(); // notify constructor that this thread has started std::vector buff(insane_mtu); while (not boost::this_thread::interruption_requested()){ if (wait_for_recv_ready(_client_socket->native())){ @@ -172,6 +167,8 @@ private: asio::ip::udp::endpoint _endpoint; boost::mutex _endpoint_mutex; socket_type _server_socket, _client_socket; + boost::mutex spawn_mutex; + boost::condition_variable wait_for_thread; }; -- cgit v1.2.3 From 8f0f045cdac16ae84bc446b230beb2b651428294 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Thu, 5 Dec 2013 08:46:22 -0800 Subject: network_relay: added #include necessary for older versions of Boost on Windows --- host/examples/network_relay.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'host/examples/network_relay.cpp') diff --git a/host/examples/network_relay.cpp b/host/examples/network_relay.cpp index fc1ebd91d..0a67bbf09 100644 --- a/host/examples/network_relay.cpp +++ b/host/examples/network_relay.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010-2012 Ettus Research LLC +// Copyright 2010-2013 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3