Skip to content

Fixes #615 Remove expired() to remove race condition #860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions host/lib/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,17 @@ device::sptr device::make(const device_addr_t& hint, device_filter_t filter, siz
static uhd::dict<size_t, std::weak_ptr<device>> hash_to_device;

// try to find an existing device
if (hash_to_device.has_key(dev_hash) and not hash_to_device[dev_hash].expired()) {
return hash_to_device[dev_hash].lock();
} else {
// Add keys from the config files (note: the user-defined keys will
// always be applied, see also get_usrp_args()
// Then, create and register a new device.
device::sptr dev = maker(prefs::get_usrp_args(dev_addr));
hash_to_device[dev_hash] = dev;
return dev;
if (hash_to_device.has_key(dev_hash)) {
if (device::sptr p = hash_to_device[dev_hash].lock())
return p;
}

// Add keys from the config files (note: the user-defined keys will
// always be applied, see also get_usrp_args()
// Then, create and register a new device.
device::sptr dev = maker(prefs::get_usrp_args(dev_addr));
hash_to_device[dev_hash] = dev;
return dev;
}

uhd::property_tree::sptr device::get_tree(void) const
Expand Down
7 changes: 3 additions & 4 deletions host/lib/rfnoc/rfnoc_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,10 +1101,9 @@ rfnoc_graph::sptr make_rfnoc_graph(

// Check if a graph was already created for this device
std::lock_guard<std::mutex> lock(_map_mutex);
if (dev_to_graph.count(dev) and not dev_to_graph[dev].expired()) {
graph = dev_to_graph[dev].lock();
if (graph != nullptr) {
return graph;
if (dev_to_graph.count(dev)) {
if (rfnoc_graph::sptr p = dev_to_graph[dev].lock()) {
return p;
}
}

Expand Down
9 changes: 5 additions & 4 deletions host/lib/transport/libusb1_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ libusb::session::sptr libusb::session::get_global_session(void)
std::lock_guard<std::mutex> lock(global_session_mutex);

// not expired -> get existing session
if (not global_session.expired())
return global_session.lock();
if (libusb::session::sptr p = global_session.lock())
return p;

// create a new global session
sptr new_global_session(new libusb_session_impl());
Expand Down Expand Up @@ -357,8 +357,9 @@ libusb::device_handle::sptr libusb::device_handle::get_cached_handle(device::spt
std::lock_guard<std::mutex> lock(mutex);

// not expired -> get existing handle
if (handles.has_key(dev->get()) and not handles[dev->get()].expired()) {
return handles[dev->get()].lock();
if (handles.has_key(dev->get())) {
if (libusb::device_handle::sptr p = handles[dev->get()].lock())
return p;
}

// create a new cached handle
Expand Down
24 changes: 12 additions & 12 deletions host/lib/usrp/b200/b200_io_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ size_t b200_impl::max_chan_count(const std::string& direction /* = "" */)
{
size_t max_count = 0;
for (radio_perifs_t& perif : _radio_perifs) {
if ((direction == "RX" or direction.empty())
and not perif.rx_streamer.expired()) {
std::shared_ptr<sph::recv_packet_streamer> rx_streamer =
std::dynamic_pointer_cast<sph::recv_packet_streamer>(
perif.rx_streamer.lock());
max_count = std::max(max_count, rx_streamer->get_num_channels());
if (direction == "RX" or direction.empty()) {
if (auto p = perif.rx_streamer.lock()) {
std::shared_ptr<sph::recv_packet_streamer> rx_streamer =
std::dynamic_pointer_cast<sph::recv_packet_streamer>(p);
max_count = std::max(max_count, rx_streamer->get_num_channels());
}
}
if ((direction == "TX" or direction.empty())
and not perif.tx_streamer.expired()) {
std::shared_ptr<sph::send_packet_streamer> tx_streamer =
std::dynamic_pointer_cast<sph::send_packet_streamer>(
perif.tx_streamer.lock());
max_count = std::max(max_count, tx_streamer->get_num_channels());
if (direction == "TX" or direction.empty()) {
if (auto p = perif.tx_streamer.lock()) {
std::shared_ptr<sph::send_packet_streamer> tx_streamer =
std::dynamic_pointer_cast<sph::send_packet_streamer>(p);
max_count = std::max(max_count, tx_streamer->get_num_channels());
}
}
}
return max_count;
Expand Down
8 changes: 3 additions & 5 deletions host/lib/usrp/multi_usrp_rfnoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2878,11 +2878,9 @@ multi_usrp::sptr make_rfnoc_device(

// Check if a multi_usrp was already created for this device
std::lock_guard<std::mutex> lock(_map_mutex);
if (graph_to_musrp.count(graph) and not graph_to_musrp[graph].expired()) {
musrp = graph_to_musrp[graph].lock();
if (musrp) {
return musrp;
}
if (graph_to_musrp.count(graph)) {
if (multi_usrp::sptr p = graph_to_musrp[graph].lock())
return p;
}

// Create a new musrp
Expand Down