aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-04-26 12:04:07 -0700
committerJosh Blum <josh@joshknows.com>2011-04-26 12:04:07 -0700
commit4335003e2e7d704f5f1d229b6a08cdb97088f785 (patch)
tree90c7241733a7d6f369f9b24d2890ed0e824ef90e /host
parent59eae14de9361f2f7f9c317a584021a5f8111328 (diff)
downloaduhd-4335003e2e7d704f5f1d229b6a08cdb97088f785.tar.gz
uhd-4335003e2e7d704f5f1d229b6a08cdb97088f785.tar.bz2
uhd-4335003e2e7d704f5f1d229b6a08cdb97088f785.zip
uhd: added scoped lock to device find and make (for thread safety)
Diffstat (limited to 'host')
-rw-r--r--host/lib/device.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/host/lib/device.cpp b/host/lib/device.cpp
index 1b3daa103..b2b0238d2 100644
--- a/host/lib/device.cpp
+++ b/host/lib/device.cpp
@@ -25,10 +25,13 @@
#include <boost/weak_ptr.hpp>
#include <boost/functional/hash.hpp>
#include <boost/tuple/tuple.hpp>
+#include <boost/thread/mutex.hpp>
#include <iostream>
using namespace uhd;
+static boost::mutex _device_mutex;
+
/***********************************************************************
* Helper Functions
**********************************************************************/
@@ -70,6 +73,8 @@ void device::register_device(
* Discover
**********************************************************************/
device_addrs_t device::find(const device_addr_t &hint){
+ boost::mutex::scoped_lock lock(_device_mutex);
+
device_addrs_t device_addrs;
BOOST_FOREACH(const dev_fcn_reg_t &fcn, get_dev_fcn_regs()){
@@ -93,6 +98,8 @@ device_addrs_t device::find(const device_addr_t &hint){
* Make
**********************************************************************/
device::sptr device::make(const device_addr_t &hint, size_t which){
+ boost::mutex::scoped_lock lock(_device_mutex);
+
typedef boost::tuple<device_addr_t, make_t> dev_addr_make_t;
std::vector<dev_addr_make_t> dev_addr_makers;