commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 09/148: Refactored timeout handling


From: git
Subject: [Commit-gnuradio] [gnuradio] 09/148: Refactored timeout handling
Date: Mon, 15 Aug 2016 00:47:19 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

nwest pushed a commit to annotated tag old_usrp_devel_udp
in repository gnuradio.

commit 541b4a46474e398656e0a5e36c1ebe7dc06ea2ff
Author: Johnathan Corgan <address@hidden>
Date:   Sat Oct 31 06:51:50 2009 -0700

    Refactored timeout handling
---
 gruel/src/include/gruel/thread.h                    |  6 +++++-
 gruel/src/lib/Makefile.am                           |  1 +
 gruel/src/{include/gruel/thread.h => lib/thread.cc} | 20 ++++++++++----------
 usrp2/host/lib/control.cc                           | 11 +++++------
 usrp2/host/lib/usrp2_impl.cc                        |  2 +-
 5 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h
index dc10d41..53423e2 100644
--- a/gruel/src/include/gruel/thread.h
+++ b/gruel/src/include/gruel/thread.h
@@ -29,7 +29,11 @@ namespace gruel {
   typedef boost::mutex                     mutex;
   typedef boost::unique_lock<boost::mutex> scoped_lock;
   typedef boost::condition_variable        condition_variable;
-  typedef boost::posix_time::time_duration duration;
+
+  /*!
+   * Returns absolute time 'secs' into the future
+   */
+  boost::system_time get_new_timeout(double secs);
 
 } /* namespace gruel */
 
diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am
index b21f802..2b26017 100644
--- a/gruel/src/lib/Makefile.am
+++ b/gruel/src/lib/Makefile.am
@@ -45,6 +45,7 @@ MSG_LIB = msg/libmsg.la
 libgruel_la_SOURCES =                  \
        realtime.cc                     \
        sys_pri.cc                      \
+       thread.cc                       \
        thread_body_wrapper.cc          \
        thread_group.cc
 
diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/lib/thread.cc
similarity index 69%
copy from gruel/src/include/gruel/thread.h
copy to gruel/src/lib/thread.cc
index dc10d41..b470aae 100644
--- a/gruel/src/include/gruel/thread.h
+++ b/gruel/src/lib/thread.cc
@@ -18,19 +18,19 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
-#ifndef INCLUDED_THREAD_H
-#define INCLUDED_THREAD_H
 
-#include <boost/thread.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
+#include <gruel/thread.h>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 namespace gruel {
 
-  typedef boost::mutex                     mutex;
-  typedef boost::unique_lock<boost::mutex> scoped_lock;
-  typedef boost::condition_variable        condition_variable;
-  typedef boost::posix_time::time_duration duration;
+  boost::system_time
+  get_new_timeout(double secs)
+  {
+    return boost::get_system_time() + 
boost::posix_time::milliseconds(long(secs*1e3));
+  }
 
 } /* namespace gruel */
-
-#endif /* INCLUDED_THREAD_H */
diff --git a/usrp2/host/lib/control.cc b/usrp2/host/lib/control.cc
index a5bbc56..4f3656b 100644
--- a/usrp2/host/lib/control.cc
+++ b/usrp2/host/lib/control.cc
@@ -44,13 +44,13 @@ namespace usrp2 {
   pending_reply::wait_for_completion(double secs)
   {
     gruel::scoped_lock l(d_mutex);
-    //gruel::duration td(0, 0, secs, 0);
+    boost::system_time to(gruel::get_new_timeout(secs));
 
-    //if (!d_complete && !d_cond.timed_wait(l, td))
-    //  return 0; // timed out
+    while (!d_complete) {
+      if (!d_cond.timed_wait(l, to))
+       return 0; // timed out
+    }
 
-    // DEBUG: don't implement timeout
-    d_cond.wait(l);
     return 1;
   }
 
@@ -63,4 +63,3 @@ namespace usrp2 {
   }
   
 } // namespace usrp2
-
diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc
index d3bf66c..905b74d 100644
--- a/usrp2/host/lib/usrp2_impl.cc
+++ b/usrp2/host/lib/usrp2_impl.cc
@@ -384,7 +384,7 @@ namespace usrp2 {
     while (d_ctrl_running){
       int ctrl_recv_len = d_eth_ctrl->read_packet_dont_block(buff, 
sizeof(buff));
       if (ctrl_recv_len >= 0) handle_control_packet(buff, ctrl_recv_len);
-      boost::thread::sleep(boost::get_system_time() + 
boost::posix_time::milliseconds(long(0.05*1e3))); //50ms timeout
+      boost::thread::sleep(gruel::get_new_timeout(0.05)); //50ms timeout
     }
   }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]