commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 06/148: Common naming convention for contro


From: git
Subject: [Commit-gnuradio] [gnuradio] 06/148: Common naming convention for control and data thread stuff.
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 96b84783cffcbafa1ae2ce6c618ec32d83a230d4
Author: Josh Blum <address@hidden>
Date:   Fri Oct 30 16:42:53 2009 -0700

    Common naming convention for control and data thread stuff.
---
 usrp2/host/lib/usrp2_impl.cc   | 63 ++++++++++++++++++++++++------------------
 usrp2/host/lib/usrp2_impl.h    | 19 +++++++------
 usrp2/host/lib/usrp2_thread.cc |  2 +-
 3 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc
index 18bf404..f320b78 100644
--- a/usrp2/host/lib/usrp2_impl.cc
+++ b/usrp2/host/lib/usrp2_impl.cc
@@ -134,8 +134,8 @@ namespace usrp2 {
       d_pf_data(0), 
       d_pf_ctrl(0),
       d_interface_name(ifc),
-      d_bg_thread(0),
-      d_bg_running(false),
+      d_data_thread(0),
+      d_data_running(false),
       d_rx_seqno(-1),
       d_tx_seqno(0),
       d_next_rid(0),
@@ -145,7 +145,7 @@ namespace usrp2 {
       d_num_rx_bytes(0), 
       d_num_enqueued(0),
       d_enqueued_mutex(),
-      d_bg_pending_cond(&d_enqueued_mutex),
+      d_data_pending_cond(&d_enqueued_mutex),
       d_channel_rings(NCHANS),
       d_tx_interp(0),
       d_rx_decim(0),
@@ -173,10 +173,8 @@ namespace usrp2 {
 
     memset(d_pending_replies, 0, sizeof(d_pending_replies));
 
-    d_bg_thread = new usrp2_thread(this);
-    d_bg_thread->start();
-
-    start_ctrl();
+    start_data_thread();
+    start_ctrl_thread();
 
     // In case the USRP2 was left streaming RX
     // FIXME: only one channel right now
@@ -230,9 +228,8 @@ namespace usrp2 {
   
   usrp2::impl::~impl()
   {
-    stop_bg();
-    stop_ctrl();
-    d_bg_thread = 0; // thread class deletes itself
+    stop_data_thread();
+    stop_ctrl_thread();
     delete d_pf_data;
     delete d_pf_ctrl;
     d_eth_data->close();
@@ -360,49 +357,61 @@ namespace usrp2 {
   }
 
   // ----------------------------------------------------------------
-  //        Background loop: received packet demuxing
+  //        Background loop for handling control packets
   // ----------------------------------------------------------------
 
   void
-  usrp2::impl::start_ctrl()
+  usrp2::impl::start_ctrl_thread()
   {
-    d_ctrl_tg.create_thread(boost::bind(&usrp2::impl::ctrl_loop, this));
+    d_ctrl_tg.create_thread(boost::bind(&usrp2::impl::run_ctrl_thread, this));
   }
 
   void
-  usrp2::impl::stop_ctrl()
+  usrp2::impl::stop_ctrl_thread()
   {
     d_ctrl_running = false;
     d_ctrl_tg.join_all();
   }
 
   void
-  usrp2::impl::ctrl_loop()
+  usrp2::impl::run_ctrl_thread()
   {
     d_ctrl_running = true;
+    uint32_t buff[100];
     while (d_ctrl_running){
-      uint32_t buff[100];
       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.01*1e3))); //10ms timeout
+      boost::thread::sleep(boost::get_system_time() + 
boost::posix_time::milliseconds(long(0.05*1e3))); //50ms timeout
     }
   }
 
+  // ----------------------------------------------------------------
+  //        Background loop for handling data packets
+  // ----------------------------------------------------------------
+
+  void
+  usrp2::impl::start_data_thread(){
+    d_data_thread = new usrp2_thread(this);
+    d_data_thread->start();
+  }
+
   void
-  usrp2::impl::stop_bg()
+  usrp2::impl::stop_data_thread()
   {
-    d_bg_running = false;
-    d_bg_pending_cond.signal();
+    d_data_running = false;
+    d_data_pending_cond.signal();
     
     void *dummy_status;
-    d_bg_thread->join(&dummy_status);  
+    d_data_thread->join(&dummy_status);
+
+    d_data_thread = 0; // thread class deletes itself
   }
   
   void
-  usrp2::impl::bg_loop()
+  usrp2::impl::run_data_thread()
   {
-    d_bg_running = true;
-    while(d_bg_running) {
+    d_data_running = true;
+    while(d_data_running) {
       DEBUG_LOG(":");
       // Receive available frames from ethernet buffer.  Handler will
       // process control frames, enqueue data packets in channel
@@ -416,11 +425,11 @@ namespace usrp2 {
       // will signal this thread to continue.
       {
         omni_mutex_lock l(d_enqueued_mutex);
-        while(d_num_enqueued > 0 && d_bg_running)
-         d_bg_pending_cond.wait();
+        while(d_num_enqueued > 0 && d_data_running)
+         d_data_pending_cond.wait();
       }
     }
-    d_bg_running = false;
+    d_data_running = false;
   }
   
   //
diff --git a/usrp2/host/lib/usrp2_impl.h b/usrp2/host/lib/usrp2_impl.h
index 97aa3d8..0dba663 100644
--- a/usrp2/host/lib/usrp2_impl.h
+++ b/usrp2/host/lib/usrp2_impl.h
@@ -65,8 +65,8 @@ namespace usrp2 {
 
     std::string    d_interface_name;
     std::string    d_addr;       // FIXME: use u2_mac_addr_t instead
-    usrp2_thread  *d_bg_thread;
-    volatile bool  d_bg_running; // TODO: multistate if needed
+    usrp2_thread  *d_data_thread;
+    volatile bool  d_data_running; // TODO: multistate if needed
     
     int            d_rx_seqno;
     int            d_tx_seqno;
@@ -78,7 +78,7 @@ namespace usrp2 {
 
     unsigned int   d_num_enqueued;
     omni_mutex     d_enqueued_mutex;
-    omni_condition d_bg_pending_cond;
+    omni_condition d_data_pending_cond;
 
     // all pending_replies are stack allocated, thus no possibility of leaking 
these
     pending_reply *d_pending_replies[NRIDS]; // indexed by 8-bit reply id
@@ -102,13 +102,14 @@ namespace usrp2 {
     void dec_enqueued() {
       omni_mutex_lock l(d_enqueued_mutex);
       if (--d_num_enqueued == 0)
-        d_bg_pending_cond.signal();
+        d_data_pending_cond.signal();
     }
     
     static bool parse_mac_addr(const std::string &s, u2_mac_addr_t *p);
     void init_etf_data_hdrs(u2_eth_packet_t *p, const std::string &dst, int 
word0_flags, int chan, uint32_t timestamp);
     void init_etf_ctrl_hdrs(u2_eth_packet_t *p, const std::string &dst, int 
word0_flags, uint32_t timestamp);
-    void stop_bg();
+    void start_data_thread();
+    void stop_data_thread();
     void init_config_rx_v2_cmd(op_config_rx_v2_cmd *cmd);
     void init_config_tx_v2_cmd(op_config_tx_v2_cmd *cmd);
     bool transmit_cmd_and_wait(void *cmd, size_t len, pending_reply *p, double 
secs=0.0);
@@ -122,15 +123,15 @@ namespace usrp2 {
     //control thread stuff
     boost::thread_group d_ctrl_tg;
     volatile bool d_ctrl_running;
-    void start_ctrl();
-    void stop_ctrl();
-    void ctrl_loop();
+    void start_ctrl_thread();
+    void stop_ctrl_thread();
+    void run_ctrl_thread();
 
   public:
     impl(const std::string &ifc, props *p, size_t rx_bufsize);
     ~impl();
     
-    void bg_loop();
+    void run_data_thread();
 
     std::string mac_addr() const { return d_addr; } // FIXME: convert from 
u2_mac_addr_t
     std::string interface_name() const { return d_interface_name; }
diff --git a/usrp2/host/lib/usrp2_thread.cc b/usrp2/host/lib/usrp2_thread.cc
index d147703..ab0982d 100644
--- a/usrp2/host/lib/usrp2_thread.cc
+++ b/usrp2/host/lib/usrp2_thread.cc
@@ -55,7 +55,7 @@ namespace usrp2 {
       std::cerr << "usrp2: failed to enable realtime scheduling" << std::endl; 
   
 
     // This is the first code to run in the new thread context.
-    d_u2->bg_loop();
+    d_u2->run_data_thread();
     
     return 0;
   }



reply via email to

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