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/transport/libusb1_zero_copy.cpp | |
| 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/transport/libusb1_zero_copy.cpp')
| -rw-r--r-- | host/lib/transport/libusb1_zero_copy.cpp | 8 | 
1 files changed, 6 insertions, 2 deletions
| diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 9f38ce97b..fe6936c7e 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -24,6 +24,7 @@  #include <boost/function.hpp>  #include <boost/foreach.hpp>  #include <boost/thread/thread.hpp> +#include <boost/thread/barrier.hpp>  #include <list>  #include <iostream> @@ -191,9 +192,11 @@ public:          //spawn the event handler threads          size_t concurrency = hints.cast<size_t>("concurrency_hint", 1); +        boost::barrier spawn_barrier(concurrency+1);          for (size_t i = 0; i < concurrency; i++) _thread_group.create_thread( -            boost::bind(&libusb_zero_copy_impl::run_event_loop, this) +            boost::bind(&libusb_zero_copy_impl::run_event_loop, this, boost::ref(spawn_barrier))          ); +        spawn_barrier.wait();      }      ~libusb_zero_copy_impl(void){ @@ -263,7 +266,8 @@ private:      boost::thread_group _thread_group;      bool _threads_running; -    void run_event_loop(void){ +    void run_event_loop(boost::barrier &spawn_barrier){ +        spawn_barrier.wait();          set_thread_priority_safe();          libusb_context *context = libusb::session::get_global_session()->get_context();          _threads_running = true; | 
