diff options
author | Josh Blum <josh@joshknows.com> | 2010-09-26 20:23:23 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-09-26 20:23:23 -0700 |
commit | 0816925695aa69a1ae344863fef47d239b3ec8af (patch) | |
tree | 22abcd826c9ded4e01e16265894d68be1dbc58b4 /host/lib/transport/libusb1_base.cpp | |
parent | dc8bcfde805228ed5d00334ce44c6c0684dcfe2c (diff) | |
download | uhd-0816925695aa69a1ae344863fef47d239b3ec8af.tar.gz uhd-0816925695aa69a1ae344863fef47d239b3ec8af.tar.bz2 uhd-0816925695aa69a1ae344863fef47d239b3ec8af.zip |
usb: zero copy work, multiple endpoints with single context, async io
Heavy work on the zero copy interface and endpoint wrappers to properly use the async io.
The global libusb session starts a thread to run the event handler,
the async callbacks push completed transfers onto a thread-safe bounded buffer.
The managed buffer creation routines use the bounded buffer to efficiently pop off completed transfers.
works on linux, throws a weird exception on cleanup
Diffstat (limited to 'host/lib/transport/libusb1_base.cpp')
-rw-r--r-- | host/lib/transport/libusb1_base.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp index 5ff996642..26e864459 100644 --- a/host/lib/transport/libusb1_base.cpp +++ b/host/lib/transport/libusb1_base.cpp @@ -20,6 +20,7 @@ #include <uhd/types/dict.hpp> #include <boost/weak_ptr.hpp> #include <boost/foreach.hpp> +#include <boost/thread.hpp> #include <iostream> using namespace uhd::transport; @@ -32,9 +33,12 @@ public: libusb_session_impl(void){ UHD_ASSERT_THROW(libusb_init(&_context) == 0); libusb_set_debug(_context, debug_level); + _thread_group.create_thread(boost::bind(&libusb_session_impl::run_event_loop, this)); } ~libusb_session_impl(void){ + _running = false; + _thread_group.join_all(); libusb_exit(_context); } @@ -44,6 +48,18 @@ public: private: libusb_context *_context; + boost::thread_group _thread_group; + bool _running; + + void run_event_loop(void){ + _running = true; + timeval tv; + while(_running){ + tv.tv_sec = 0; + tv.tv_usec = 100000; //100ms + libusb_handle_events_timeout(this->get_context(), &tv); + } + } }; libusb::session::sptr libusb::session::get_global_session(void){ |