aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/transport/libusb1_base.cpp
diff options
context:
space:
mode:
authorNick Foster <nick@nerdnetworks.org>2010-10-05 11:13:25 -0700
committerNick Foster <nick@nerdnetworks.org>2010-10-05 11:14:45 -0700
commite4d088fa9169eef81473cb7d83bda7c82bc5d243 (patch)
tree0798f4c0863bcb27ff4164f9e2fcc2ccd7bf80d3 /host/lib/transport/libusb1_base.cpp
parent6dd502737bcf6e59933be01720672db9a496803b (diff)
parentbd3bd0dfbc1a87af5839c9b23450434cfb9c763c (diff)
downloaduhd-e4d088fa9169eef81473cb7d83bda7c82bc5d243.tar.gz
uhd-e4d088fa9169eef81473cb7d83bda7c82bc5d243.tar.bz2
uhd-e4d088fa9169eef81473cb7d83bda7c82bc5d243.zip
Merge branch 'master' of ettus.sourcerepo.com:ettus/uhdpriv into usrp2p
Conflicts: host/lib/ic_reg_maps/CMakeLists.txt host/lib/usrp/usrp2/io_impl.cpp
Diffstat (limited to 'host/lib/transport/libusb1_base.cpp')
-rw-r--r--host/lib/transport/libusb1_base.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp
index 49f524a32..1dd0b48e8 100644
--- a/host/lib/transport/libusb1_base.cpp
+++ b/host/lib/transport/libusb1_base.cpp
@@ -35,7 +35,9 @@ public:
libusb_session_impl(void){
UHD_ASSERT_THROW(libusb_init(&_context) == 0);
libusb_set_debug(_context, debug_level);
+ _mutex.lock();
_thread_group.create_thread(boost::bind(&libusb_session_impl::run_event_loop, this));
+ _mutex.lock();
}
~libusb_session_impl(void){
@@ -52,11 +54,13 @@ private:
libusb_context *_context;
boost::thread_group _thread_group;
bool _running;
+ boost::mutex _mutex;
void run_event_loop(void){
set_thread_priority_safe();
_running = true;
timeval tv;
+ _mutex.unlock();
while(_running){
tv.tv_sec = 0;
tv.tv_usec = 100000; //100ms
@@ -213,15 +217,21 @@ private:
libusb::device_handle::sptr libusb::device_handle::get_cached_handle(device::sptr dev){
static uhd::dict<libusb_device *, boost::weak_ptr<device_handle> > handles;
- //not expired -> get existing session
+ //not expired -> get existing handle
if (handles.has_key(dev->get()) and not handles[dev->get()].expired()){
return handles[dev->get()].lock();
}
- //create a new global session
- sptr new_handle(new libusb_device_handle_impl(dev));
- handles[dev->get()] = new_handle;
- return new_handle;
+ //create a new cached handle
+ try{
+ sptr new_handle(new libusb_device_handle_impl(dev));
+ handles[dev->get()] = new_handle;
+ return new_handle;
+ }
+ catch(const std::exception &e){
+ std::cerr << "USB open failed: see the application notes for your device." << std::endl;
+ throw std::runtime_error(e.what());
+ }
}
/***********************************************************************