From 14c5812fd773108a75f568d11d9ae4d833de1aeb Mon Sep 17 00:00:00 2001 From: Mark Meserve Date: Wed, 16 Oct 2019 13:28:58 -0500 Subject: 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. --- host/lib/transport/libusb1_base.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'host/lib') 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 #include #include +#include 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 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 lock(global_session_mutex); // not expired -> get existing session if (not global_session.expired()) -- cgit v1.2.3