[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8412 - in usrp2/branches/developers/jcorgan/u2/host:
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8412 - in usrp2/branches/developers/jcorgan/u2/host: apps gr-usrp2 lib |
Date: |
Mon, 12 May 2008 21:50:06 -0600 (MDT) |
Author: jcorgan
Date: 2008-05-12 21:50:06 -0600 (Mon, 12 May 2008)
New Revision: 8412
Modified:
usrp2/branches/developers/jcorgan/u2/host/apps/rx_streaming_samples.cc
usrp2/branches/developers/jcorgan/u2/host/apps/tx_samples.cc
usrp2/branches/developers/jcorgan/u2/host/apps/u2_burn_mac_addr.cc
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.cc
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.h
usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
Log:
Convert usrp2_basic to use shared pointers.
Modified: usrp2/branches/developers/jcorgan/u2/host/apps/rx_streaming_samples.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/apps/rx_streaming_samples.cc
2008-05-13 02:27:35 UTC (rev 8411)
+++ usrp2/branches/developers/jcorgan/u2/host/apps/rx_streaming_samples.cc
2008-05-13 03:50:06 UTC (rev 8412)
@@ -312,7 +312,7 @@
}
}
- usrp2_basic *u2 = new usrp2_basic();
+ usrp2_basic_sptr u2 = usrp2_make_basic();
if (!u2->open(interface)){
std::cerr << "couldn't open " << interface << std::endl;
Modified: usrp2/branches/developers/jcorgan/u2/host/apps/tx_samples.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/apps/tx_samples.cc
2008-05-13 02:27:35 UTC (rev 8411)
+++ usrp2/branches/developers/jcorgan/u2/host/apps/tx_samples.cc
2008-05-13 03:50:06 UTC (rev 8412)
@@ -160,7 +160,7 @@
return 1;
}
- usrp2_basic *u2 = new usrp2_basic();
+ usrp2_basic_sptr u2 = usrp2_make_basic();
if (!u2->open(interface)){
std::cerr << "couldn't open " << interface << std::endl;
Modified: usrp2/branches/developers/jcorgan/u2/host/apps/u2_burn_mac_addr.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/apps/u2_burn_mac_addr.cc
2008-05-13 02:27:35 UTC (rev 8411)
+++ usrp2/branches/developers/jcorgan/u2/host/apps/u2_burn_mac_addr.cc
2008-05-13 03:50:06 UTC (rev 8412)
@@ -79,7 +79,7 @@
}
- usrp2_basic *u2 = new usrp2_basic();
+ usrp2_basic_sptr u2 = usrp2_make_basic();
if (!u2->open(interface)){
std::cerr << "couldn't open " << interface << std::endl;
Modified:
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
2008-05-13 02:27:35 UTC (rev 8411)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
2008-05-13 03:50:06 UTC (rev 8412)
@@ -39,7 +39,7 @@
: gr_sync_block(name,
gr_make_io_signature(0, 0, 0),
output_signature),
- d_u2(0)
+ d_u2(usrp2_basic_sptr())
{
op_id_reply_t id;
@@ -67,8 +67,6 @@
usrp2_source_base::~usrp2_source_base ()
{
- if (d_u2)
- release_usrp2_basic(d_u2);
}
int
Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
2008-05-13 02:27:35 UTC (rev 8411)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
2008-05-13 03:50:06 UTC (rev 8412)
@@ -36,7 +36,7 @@
const std::string &mac = "")
throw (std::runtime_error);
- usrp2_basic *d_u2;
+ usrp2_basic_sptr d_u2;
public:
~usrp2_source_base();
Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.cc
2008-05-13 02:27:35 UTC (rev 8411)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.cc
2008-05-13 03:50:06 UTC (rev 8412)
@@ -26,13 +26,19 @@
#include <usrp2_table.h>
#include <omnithread.h>
+#include <boost/weak_ptr.hpp>
#include <stdexcept>
+#include <iostream>
+#define USRP2_TABLE_DEBUG 1
+
static omni_mutex lock;
+typedef boost::weak_ptr<usrp2_basic> usrp2_basic_wptr;
+
typedef struct {
u2_mac_addr_t addr;
- usrp2_basic *u2;
+ usrp2_basic_wptr u2;
} entry_t;
typedef std::vector<entry_t> entry_vector_t;
@@ -40,34 +46,35 @@
static entry_vector_t s_table;
-usrp2_basic *
+usrp2_basic_sptr
find_or_create_usrp2_basic(const std::string &ifc, const u2_mac_addr_t &addr)
{
omni_mutex_lock l(lock);
-
- for (entry_viter_t e = s_table.begin(); e != s_table.end(); e++) {
- if (e->addr == addr)
- return e->u2;
+ usrp2_basic_sptr u2;
+
+ for (entry_viter_t en = s_table.begin(); en != s_table.end(); en++) {
+ if (en->addr == addr) {
+ if (USRP2_TABLE_DEBUG)
+ std::cout << "find_or_create_usrp2_basic: found for " << addr <<
std::endl;
+ try {
+ return usrp2_basic_sptr(en->u2);
+ }
+ catch (boost::bad_weak_ptr e) { // Went out of scope
+ u2 = usrp2_make_basic();
+ en->u2 = usrp2_basic_wptr(u2);
+ return u2;
+ }
+ }
}
- entry_t e;
- e.addr = addr;
- e.u2 = new usrp2_basic(); // In future will use ifc and addr
- s_table.push_back(e);
- return e.u2;
-}
+ if (USRP2_TABLE_DEBUG)
+ std::cout << "find_or_create_usrp2_basic: creating new usrp2_basic for "
+ << addr << std::endl;
-void
-release_usrp2_basic(usrp2_basic *u2)
-{
- omni_mutex_lock l(lock);
-
- for (entry_viter_t e = s_table.begin(); e != s_table.end(); e++) {
- if (e->u2 == u2) {
- s_table.erase(e);
- return;
- }
- }
-
- throw std::runtime_error("Attempt to release non-existent usrp2_basic");
+ entry_t en;
+ en.addr = addr;
+ u2 = usrp2_make_basic();
+ en.u2 = usrp2_basic_wptr(u2);
+ s_table.push_back(en);
+ return u2;
}
Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.h
2008-05-13 02:27:35 UTC (rev 8411)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.h
2008-05-13 03:50:06 UTC (rev 8412)
@@ -25,7 +25,6 @@
#include <usrp2_basic.h>
-usrp2_basic *find_or_create_usrp2_basic(const std::string &ifc, const
u2_mac_addr_t &addr);
-void release_usrp2_basic(usrp2_basic *u2);
+usrp2_basic_sptr find_or_create_usrp2_basic(const std::string &ifc, const
u2_mac_addr_t &addr);
#endif /* INCLUDED_USRP2_TABLE_H */
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
2008-05-13 02:27:35 UTC (rev 8411)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
2008-05-13 03:50:06 UTC (rev 8412)
@@ -36,6 +36,7 @@
#include <unistd.h>
#endif
+#define USRP2_BASIC_DEBUG 1
/*
* Note, this should be considered a first cut at getting
@@ -52,15 +53,24 @@
#define MAX_PKTLEN 1512 // biggest thing USRP2 can swallow
// (14-byte ethernet hdr + 1500 byte payload)
+usrp2_basic_sptr
+usrp2_make_basic()
+{
+ return usrp2_basic_sptr(new usrp2_basic());
+}
usrp2_basic::usrp2_basic()
: d_ethernet(new GRI_ETHERNET()), d_pf(0), d_seqno(0), d_next_rid(0)
{
assert(sizeof(u2_eth_samples_t) == (size_t) MAX_PKTLEN);
+ if (USRP2_BASIC_DEBUG)
+ std::cout << "usrp2_basic: constructor" << std::endl;
}
usrp2_basic::~usrp2_basic()
{
+ if (USRP2_BASIC_DEBUG)
+ std::cout << "usrp2_basic: destructor" << std::endl;
delete d_pf;
delete d_ethernet;
}
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-13
02:27:35 UTC (rev 8411)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-13
03:50:06 UTC (rev 8412)
@@ -50,9 +50,17 @@
: baseband_freq(0), dxc_freq(0), residual_freq(0),
spectrum_inverted(false) {}
};
+class usrp2_basic;
+typedef boost::shared_ptr<usrp2_basic> usrp2_basic_sptr;
+usrp2_basic_sptr usrp2_make_basic();
+
class usrp2_basic : public boost::noncopyable
{
+private:
+ friend usrp2_basic_sptr usrp2_make_basic();
+ usrp2_basic();
+
GRI_ETHERNET *d_ethernet;
gri_pktfilter *d_pf;
int d_seqno;
@@ -95,7 +103,6 @@
// ---- Instance methods ----
- usrp2_basic();
~usrp2_basic();
/*!
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8412 - in usrp2/branches/developers/jcorgan/u2/host: apps gr-usrp2 lib,
jcorgan <=