commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10964 - gnuradio/branches/developers/eb/t371/usrp/hos


From: eb
Subject: [Commit-gnuradio] r10964 - gnuradio/branches/developers/eb/t371/usrp/host/lib/legacy
Date: Tue, 5 May 2009 15:47:47 -0600 (MDT)

Author: eb
Date: 2009-05-05 15:47:46 -0600 (Tue, 05 May 2009)
New Revision: 10964

Modified:
   gnuradio/branches/developers/eb/t371/usrp/host/lib/legacy/db_xcvr2450.cc
Log:
reworked table to use weak pointers

Modified: 
gnuradio/branches/developers/eb/t371/usrp/host/lib/legacy/db_xcvr2450.cc
===================================================================
--- gnuradio/branches/developers/eb/t371/usrp/host/lib/legacy/db_xcvr2450.cc    
2009-05-05 21:21:18 UTC (rev 10963)
+++ gnuradio/branches/developers/eb/t371/usrp/host/lib/legacy/db_xcvr2450.cc    
2009-05-05 21:47:46 UTC (rev 10964)
@@ -21,6 +21,8 @@
 #include <db_xcvr2450.h>
 #include <db_base_impl.h>
 #include <cmath>
+#include <boost/thread.hpp>
+#include <boost/weak_ptr.hpp>
 
 #if 0
 #define LO_OFFSET 4.25e6
@@ -66,6 +68,10 @@
 struct xcvr2450_key {
   std::string serial_no;
   int which;
+
+  bool operator==(const xcvr2450_key &x){
+    return x.serial_no ==serial_no && x.which == which;
+  }
 };
 
 class xcvr2450
@@ -104,8 +110,6 @@
   xcvr2450(usrp_basic_sptr usrp, int which);
   ~xcvr2450();
 
-  bool operator==(xcvr2450_key x);
-
   void set_reg_standby();
   
   // Integer-Divider Ratio (3)
@@ -239,17 +243,6 @@
   usrp()->common_write_atr_rxval(C_RX, d_which, RX_SAFE_IO);
 }
 
-bool
-xcvr2450::operator==(xcvr2450_key x)
-{
-  if((x.serial_no == usrp()->serial_number()) && (x.which == d_which)) {
-    return true;
-  }
-  else {
-    return false;
-  }
-}
-
 void
 xcvr2450::set_reg_standby()
 {
@@ -468,7 +461,7 @@
   double div = vco_freq/phdet_freq;
   d_int_div = int(floor(div));
   d_frac_div = int((div-d_int_div)*65536.0);
-  double actual_freq = phdet_freq*(d_int_div+(d_frac_div/65536.0))/scaler;
+  // double actual_freq = phdet_freq*(d_int_div+(d_frac_div/65536.0))/scaler;
   
   //printf("RF=%f VCO=%f R=%d PHD=%f DIV=%3.5f I=%3d F=%5d ACT=%f\n",
   //    target_freq, vco_freq, d_ref_div, phdet_freq,
@@ -560,32 +553,49 @@
 /*****************************************************************************/
 
 
-//_xcvr2450_inst = weakref.WeakValueDictionary()
-std::vector<xcvr2450_sptr> _xcvr2450_inst;
+struct xcvr2450_table_entry {
+  xcvr2450_key                         key;
+  boost::weak_ptr<xcvr2450>    value;
 
-xcvr2450_sptr
+  xcvr2450_table_entry(const xcvr2450_key &_key, boost::weak_ptr<xcvr2450> 
_value)
+    : key(_key), value(_value) {}
+};
+
+typedef std::vector<xcvr2450_table_entry> xcvr2450_table;
+
+static boost::mutex s_table_mutex;
+static xcvr2450_table s_table;
+
+static xcvr2450_sptr
 _get_or_make_xcvr2450(usrp_basic_sptr usrp, int which)
 {
-  xcvr2450_sptr inst;
   xcvr2450_key key = {usrp->serial_number(), which};
-  std::vector<xcvr2450_sptr>::iterator itr; // =
-  //std::find(_xcvr2450_inst.begin(), _xcvr2450_inst.end(), key);
 
-  for(itr = _xcvr2450_inst.begin(); itr != _xcvr2450_inst.end(); itr++) {
-    if(*(*itr) == key) {
-      //printf("Using existing xcvr2450 instance\n");
-      inst = *itr;
-      break;
+  boost::mutex::scoped_lock    guard(s_table_mutex);
+
+  for (xcvr2450_table::iterator p = s_table.begin(); p != s_table.end();){
+    if (p->value.expired())    // weak pointer is now dead
+      p = s_table.erase(p);    // erase it
+    else {
+      if (key == p->key){      // found it
+       std::cerr << "found xcvr2450\n";
+       return xcvr2450_sptr(p->value);
+      }
+      else                     
+       ++p;                    // keep looking
     }
   }
-  
-  if(itr == _xcvr2450_inst.end()) {
-    //printf("Creating new xcvr2450 instance\n");
-    inst = xcvr2450_sptr(new xcvr2450(usrp, which));
-    _xcvr2450_inst.push_back(inst);
-  }
 
-  return inst;
+  // We don't have the xcvr2450 we're looking for
+
+  // create a new one and stick it in the table.
+  xcvr2450_sptr r(new xcvr2450(usrp, which));
+  xcvr2450_table_entry t(key, r);
+  s_table.push_back(t);
+
+  std::cerr << "make new xcvr2450\n";
+
+  return r;
 }
 
 





reply via email to

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