aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Meserve <mark.meserve@ni.com>2019-10-16 13:28:58 -0500
committerMartin Braun <martin.braun@ettus.com>2019-10-16 14:24:14 -0700
commit14c5812fd773108a75f568d11d9ae4d833de1aeb (patch)
treeb1b0a8aff7b3592de54871b2d6171b1ee3660ab1
parentbe183dae7a5d2e5f546d699c233d17430dd315ee (diff)
downloaduhd-14c5812fd773108a75f568d11d9ae4d833de1aeb.tar.gz
uhd-14c5812fd773108a75f568d11d9ae4d833de1aeb.tar.bz2
uhd-14c5812fd773108a75f568d11d9ae4d833de1aeb.zip
libusb: fix global session race condition
- It was possible for two threads to generate a global session, which would cause one of them to become invalid.
-rw-r--r--host/lib/transport/libusb1_base.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp
index 83d9fe1df..d383b0a3e 100644
--- a/host/lib/transport/libusb1_base.cpp
+++ b/host/lib/transport/libusb1_base.cpp
@@ -16,6 +16,7 @@
#include <boost/weak_ptr.hpp>
#include <cstdlib>
#include <iostream>
+#include <mutex>
using namespace uhd;
using namespace uhd::transport;
@@ -86,6 +87,10 @@ libusb_session_impl::~libusb_session_impl(void)
libusb::session::sptr libusb::session::get_global_session(void)
{
static boost::weak_ptr<session> global_session;
+ // this mutex is to ensure a global session is not currently being created
+ // before checking for the existence of one
+ static std::mutex global_session_mutex;
+ std::lock_guard<std::mutex> lock(global_session_mutex);
// not expired -> get existing session
if (not global_session.expired())