From 5d040bc94b40cab5420303f959695d89fe83e031 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Fri, 4 Sep 2009 01:51:29 -0700 Subject: Fix race condition that caused commands such as stop_rx_streaming to fail. This fixes the bulk of the problem. Next step is to drop data packets while waiting for the reply. --- usrp2/host/lib/control.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'usrp2/host/lib/control.cc') diff --git a/usrp2/host/lib/control.cc b/usrp2/host/lib/control.cc index 4b8597c60..bb71f79c2 100644 --- a/usrp2/host/lib/control.cc +++ b/usrp2/host/lib/control.cc @@ -30,26 +30,34 @@ namespace usrp2 { pending_reply::pending_reply(unsigned int rid, void *buffer, size_t len) - : d_rid(rid), d_mutex(), d_cond(&d_mutex), d_buffer(buffer), d_len(len) + : d_rid(rid), d_buffer(buffer), d_len(len), d_mutex(), d_cond(&d_mutex), + d_complete(false) { } pending_reply::~pending_reply() { - signal(); // Needed? + notify_completion(); // Needed? } int - pending_reply::wait(double secs) + pending_reply::wait_for_completion(double secs) { - omni_mutex_lock l(d_mutex); omni_time abs_timeout = omni_time::time(omni_time(secs)); - return d_cond.timedwait(abs_timeout.d_secs, abs_timeout.d_nsecs); + omni_mutex_lock l(d_mutex); + while (!d_complete){ + int r = d_cond.timedwait(abs_timeout.d_secs, abs_timeout.d_nsecs); + if (r == 0) // timed out + return 0; + } + return 1; } void - pending_reply::signal() + pending_reply::notify_completion() { + omni_mutex_lock l(d_mutex); + d_complete = true; d_cond.signal(); } -- cgit