diff options
| author | Martin Braun <martin.braun@ettus.com> | 2018-07-20 10:55:46 -0700 | 
|---|---|---|
| committer | Brent Stapleton <brent.stapleton@ettus.com> | 2018-07-31 10:05:03 -0700 | 
| commit | ab1c74c7e4cc7f0fa339be7b6685109045f6f878 (patch) | |
| tree | b703196c9171d33f6b68d2decd816c8b23667f0b /host/lib | |
| parent | 491e28c956b69dce24c3c62b534070fa267940e6 (diff) | |
| download | uhd-ab1c74c7e4cc7f0fa339be7b6685109045f6f878.tar.gz uhd-ab1c74c7e4cc7f0fa339be7b6685109045f6f878.tar.bz2 uhd-ab1c74c7e4cc7f0fa339be7b6685109045f6f878.zip  | |
lib: device: Parallelize device discovery
Diffstat (limited to 'host/lib')
| -rw-r--r-- | host/lib/device.cpp | 30 | 
1 files changed, 19 insertions, 11 deletions
diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 90d7ae374..d2d98718e 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -14,13 +14,14 @@  #include <uhd/utils/algorithm.hpp>  #include <uhdlib/utils/prefs.hpp> -  #include <boost/format.hpp>  #include <boost/weak_ptr.hpp>  #include <boost/functional/hash.hpp>  #include <boost/tuple/tuple.hpp>  #include <boost/thread/mutex.hpp> +#include <future> +  using namespace uhd;  static boost::mutex _device_mutex; @@ -94,17 +95,24 @@ device_addrs_t device::find(const device_addr_t &hint, device_filter_t filter){      boost::mutex::scoped_lock lock(_device_mutex);      device_addrs_t device_addrs; - -    for(const dev_fcn_reg_t &fcn:  get_dev_fcn_regs()) { +    std::vector<std::future<device_addrs_t>> find_tasks; +    for (const auto& fcn : get_dev_fcn_regs()) { +        if (filter == ANY or fcn.get<2>() == filter) { +            find_tasks.emplace_back(std::async(std::launch::async, +                [fcn, hint](){ +                    return fcn.get<0>()(hint); +                } +            )); +        } +    } +    for(auto &find_task : find_tasks) {          try { -            if (filter == ANY or fcn.get<2>() == filter) { -                device_addrs_t discovered_addrs = fcn.get<0>()(hint); -                device_addrs.insert( -                    device_addrs.begin(), -                    discovered_addrs.begin(), -                    discovered_addrs.end() -                ); -            } +            device_addrs_t discovered_addrs = find_task.get(); +            device_addrs.insert( +                device_addrs.begin(), +                discovered_addrs.begin(), +                discovered_addrs.end() +            );          }          catch (const std::exception &e) {              UHD_LOGGER_ERROR("UHD") << "Device discovery error: " << e.what();  | 
