diff options
author | Josh Blum <josh@joshknows.com> | 2011-03-31 15:00:56 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-03-31 15:00:56 -0700 |
commit | 1c5076ea68345e74de35cad43e4a4b4adf68fa15 (patch) | |
tree | ad9f49f783761e89054a7bee5a0c20c9b406da35 /host/lib/usrp/usrp1 | |
parent | 48f6e1f8aae24ee4ff3b15232cfc335b0210ed11 (diff) | |
download | uhd-1c5076ea68345e74de35cad43e4a4b4adf68fa15.tar.gz uhd-1c5076ea68345e74de35cad43e4a4b4adf68fa15.tar.bz2 uhd-1c5076ea68345e74de35cad43e4a4b4adf68fa15.zip |
uhd: implemented boost barriers on all code that creates threads
The barrier ensures that the thread must spawn before the caller exits.
Some of the code already used a mutex to accomplish this,
however cygwin chokes when a mutex is locked twice by the same thread.
Mutex implementations were replaced with the barrier implementation.
Also the barrier implementation is far cleaner.
Diffstat (limited to 'host/lib/usrp/usrp1')
-rw-r--r-- | host/lib/usrp/usrp1/soft_time_ctrl.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/host/lib/usrp/usrp1/soft_time_ctrl.cpp b/host/lib/usrp/usrp1/soft_time_ctrl.cpp index e1b671811..1bab34e7b 100644 --- a/host/lib/usrp/usrp1/soft_time_ctrl.cpp +++ b/host/lib/usrp/usrp1/soft_time_ctrl.cpp @@ -19,6 +19,7 @@ #include <uhd/transport/bounded_buffer.hpp> #include <boost/any.hpp> #include <boost/thread/thread.hpp> +#include <boost/thread/barrier.hpp> #include <boost/thread/condition_variable.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <iostream> @@ -43,10 +44,11 @@ public: _stream_on_off(stream_on_off) { //synchronously spawn a new thread - _update_mutex.lock(); //lock mutex before spawned - _thread_group.create_thread(boost::bind(&soft_time_ctrl_impl::recv_cmd_dispatcher, this)); - _update_mutex.lock(); //lock blocks until spawned - _update_mutex.unlock(); //unlock mutex before done + boost::barrier spawn_barrier(2); + _thread_group.create_thread(boost::bind( + &soft_time_ctrl_impl::recv_cmd_dispatcher, this, boost::ref(spawn_barrier)) + ); + spawn_barrier.wait(); //initialize the time to something this->set_time(time_spec_t(0.0)); @@ -175,8 +177,8 @@ public: _stream_mode = cmd.stream_mode; } - void recv_cmd_dispatcher(void){ - _update_mutex.unlock(); + void recv_cmd_dispatcher(boost::barrier &spawn_barrier){ + spawn_barrier.wait(); try{ boost::any cmd; while (true){ |