Skip to content

Commit

Permalink
boost: Remove boost header requirment.
Browse files Browse the repository at this point in the history
Back out all use of boost smart pointers, use ref_ptr
instead.  Also removed some dead code in libxipc.
This needs some testing.

Signed-off-by: Ben Greear <greearb@candelatech.com>
  • Loading branch information
greearb committed Jun 3, 2010
1 parent 9090862 commit 7fa28b3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 142 deletions.
14 changes: 5 additions & 9 deletions xorp/libxipc/xrl.hh
Expand Up @@ -26,16 +26,13 @@

#include <string>

#include <boost/weak_ptr.hpp>
#include "libxorp/ref_ptr.hh"
#include "xrl_pf.hh" // Needed for ref_ptr instantiation of XrlPFSender

#include "libxorp/exceptions.hh"
#include "xrl_atom.hh"
#include "xrl_args.hh"
#include "xrl_tokens.hh"
//#include "libxorp/ref_ptr.hh"
//#include "xrl_pf.hh" // Needed for ref_ptr instantiation of XrlPFSender

using boost::weak_ptr;

class XrlPFSender;

Expand Down Expand Up @@ -175,11 +172,11 @@ public:
bool resolved() const { return _resolved; }
void set_resolved(bool r) const { _resolved = r; }

weak_ptr<XrlPFSender> resolved_sender() const {
ref_ptr<XrlPFSender> resolved_sender() const {
return _resolved_sender;
}

void set_resolved_sender(weak_ptr<XrlPFSender> s) const {
void set_resolved_sender(ref_ptr<XrlPFSender>& s) const {
_resolved_sender = s;
}

Expand All @@ -205,8 +202,7 @@ private:
mutable XrlArgs* _argp; // XXX shouldn't be mutable
mutable int _to_finder;
mutable bool _resolved; // XXX ditto
//mutable ref_ptr<XrlPFSender> _resolved_sender; // XXX ditto
mutable weak_ptr<XrlPFSender> _resolved_sender; // XXX ditto
mutable ref_ptr<XrlPFSender> _resolved_sender; // XXX ditto

static const string _finder_protocol;
};
Expand Down
24 changes: 10 additions & 14 deletions xorp/libxipc/xrl_pf_factory.cc
Expand Up @@ -33,47 +33,43 @@
#include "xrl_pf_stcp.hh"
#include "xrl_pf_unix.hh"

//#include <boost/make_shared.hpp>
//using boost::make_shared;

// STCP senders are a special case. Constructing an STCP sender has
// real cost, unlike InProc and SUDP, so we maintain a cache of
// STCP senders with one per sender destination address.

//ref_ptr<XrlPFSender>
shared_ptr<XrlPFSender>
ref_ptr<XrlPFSender>
XrlPFSenderFactory::create_sender(EventLoop& eventloop,
const char* protocol,
const char* address)
{
debug_msg("instantiating sender pf = \"%s\", addr = \"%s\"\n",
protocol, address);
ref_ptr<XrlPFSender> rv;
try {
if (strcmp(XrlPFSTCPSender::protocol_name(), protocol) == 0) {
// XXX boost::make_shared() candidate.
return shared_ptr<XrlPFSender>(
new XrlPFSTCPSender(eventloop, address));
rv = new XrlPFSTCPSender(eventloop, address);
return rv;
}
if (strcmp(XrlPFUNIXSender::protocol_name(), protocol) == 0) {
// XXX boost::make_shared() candidate.
return shared_ptr<XrlPFSender>(
new XrlPFUNIXSender(eventloop, address));
rv = new XrlPFUNIXSender(eventloop, address);
return rv;
}
} catch (XorpException& e) {
XLOG_ERROR("XrlPFSenderFactory::create failed: %s\n", e.str().c_str());
}
return shared_ptr<XrlPFSender>();
return rv;
}

shared_ptr<XrlPFSender>
ref_ptr<XrlPFSender>
XrlPFSenderFactory::create_sender(EventLoop& eventloop,
const char* protocol_colon_address)
{
char *colon = strstr(const_cast<char*>(protocol_colon_address), ":");
ref_ptr<XrlPFSender> rv;
if (colon == 0) {
debug_msg("No colon in supposedly colon separated <protocol><address>"
"combination\n\t\"%s\".\n", protocol_colon_address);
return shared_ptr<XrlPFSender>();
return rv;
}

string protocol(protocol_colon_address, colon - protocol_colon_address);
Expand Down
8 changes: 2 additions & 6 deletions xorp/libxipc/xrl_pf_factory.hh
Expand Up @@ -27,19 +27,15 @@
#include "xrl_error.hh"
#include "xrl_pf.hh"

#include <boost/shared_ptr.hpp>

using boost::shared_ptr;

class XrlPFSenderFactory {
public:
static void startup();
static void shutdown();

static shared_ptr<XrlPFSender> create_sender(
static ref_ptr<XrlPFSender> create_sender(
EventLoop& eventloop, const char* proto_colon_addr);

static shared_ptr<XrlPFSender> create_sender(EventLoop& e,
static ref_ptr<XrlPFSender> create_sender(EventLoop& e,
const char* protocol, const char* address);
};

Expand Down
119 changes: 21 additions & 98 deletions xorp/libxipc/xrl_router.cc
Expand Up @@ -38,10 +38,6 @@

#include "sockutil.hh"

// XXX should be included nested above.
//#include <boost/shared_ptr.hpp>
//#include <boost/weak_ptr.hpp>

//
// Enable this macro to enable Xrl callback checker that checks each Xrl
// callback is dispatched just once.
Expand Down Expand Up @@ -390,9 +386,8 @@ XrlRouter::send_resolved(const Xrl& xrl,
bool direct_call)
{
try {
shared_ptr<XrlPFSender> s =
lookup_sender(xrl, const_cast<FinderDBEntry*>(dbe));
if (s == 0) {
ref_ptr<XrlPFSender> s = lookup_sender(xrl, const_cast<FinderDBEntry*>(dbe));
if (!s.get()) {
// Notify Finder client that result was bad.
_fc->uncache_result(dbe);

Expand All @@ -402,63 +397,43 @@ XrlRouter::send_resolved(const Xrl& xrl,

const Xrl& x = dbe->xrls().front();
x.set_args(xrl);
if (s != 0) {
trace_xrl("Sending ", x);
// NOTE: using s.get below breaks ref counting, but can't figure out WTF the
// callback template magic is to make it work with a ref-ptr. Either way, it appears
// the ptr may not be used anyway (it's not in send_callback, for instance)
return s->send(x, direct_call,
callback(this, &XrlRouter::send_callback,
s.get(), cb));
}

trace_xrl("Sending ", x);
// NOTE: using s.get below breaks ref counting, but can't figure out WTF the
// callback template magic is to make it work with a ref-ptr. Either way, it appears
// the ptr may not be used anyway (it's not in send_callback, for instance)
return s->send(x, direct_call,
callback(this, &XrlRouter::send_callback,
s.get(), cb));

cb->dispatch(XrlError(SEND_FAILED, "sender not instantiated"), 0);
} catch (const InvalidString&) {
cb->dispatch(XrlError(INTERNAL_ERROR, "bad factory arguments"), 0);
}
return false;
}

// XXX Return uninitialized shared_ptr, or locked shared_ptr,
// on desired XrlPFSender.
shared_ptr<XrlPFSender>
ref_ptr<XrlPFSender>
XrlRouter::lookup_sender(const Xrl& xrl, FinderDBEntry* dbe)
{
const Xrl& x = dbe->xrls().front();
shared_ptr<XrlPFSender> s;
ref_ptr<XrlPFSender> s;

// Try to use the cached pointer to the sender.
if (xrl.resolved()) {
weak_ptr<XrlPFSender> w = xrl.resolved_sender();

// Check if cached weak_ptr to sender is still valid; we may
// have lost a race on the XRLDB.
// Check if transport layer is still up for this sender.
// If good to go, return shared pointer for which we
// still hold the lock.
s = w.lock();
if (s.get() != 0 && s->alive())
return s;

// We lost the race.
s = xrl.resolved_sender();

// XXX Sanity check that this sender's protocol and endpoint
// addresses are the same as they were when the Xrl was
// instantiated.
XLOG_ASSERT(s->protocol() == x.protocol());
XLOG_ASSERT(s->address() == x.target());
if (!s.is_empty())
return s;

xrl.set_resolved(false);
xrl.set_resolved_sender(weak_ptr<XrlPFSender>());
}

// Find a new sender.
for (list< shared_ptr<XrlPFSender> >::iterator i = _senders.begin();
for (list< ref_ptr<XrlPFSender> >::iterator i = _senders.begin();
i != _senders.end(); ++i) {
s = *i;

// This XrlRouter holds the reference, so the pointer should be valid.
XLOG_ASSERT(s.get() != 0);

if (s->protocol() != x.protocol() || s->address() != x.target())
continue;

Expand All @@ -472,7 +447,6 @@ XrlRouter::lookup_sender(const Xrl& xrl, FinderDBEntry* dbe)
s->protocol(), s->address().c_str());

_senders.erase(i);
_senders2.erase(xrl.target());
break;
}

Expand All @@ -495,25 +469,15 @@ XrlRouter::lookup_sender(const Xrl& xrl, FinderDBEntry* dbe)
}

// Unable to instantiate.
if (s == 0)
return shared_ptr<XrlPFSender>();
if (!s.get())
return s;

// New sender instantiated, take lock and record state.
const Xrl& front = dbe->xrls().front();

XLOG_ASSERT(s->protocol() == front.protocol());
XLOG_ASSERT(s->address() == front.target());
_senders.push_back(s);
_senders2[xrl.target()] = s.get();

// Don't do this here as it is set in the Xrl that is stored with
// the finder client, so is not used. But if the connection needs
// to be re-established then it will be used and the state will be
// bad.
#if 0
xrl.set_resolved(true);
xrl.set_resolved_sender(s);
#endif

return s;
}
Expand All @@ -531,7 +495,8 @@ XrlRouter::resolve_callback(const XrlError& e,
if (e == XrlError::OKAY()) {
const Xrl& xrl = ds->xrl();
xrl.set_resolved(false);
xrl.set_resolved_sender(weak_ptr<XrlPFSender>());
ref_ptr<XrlPFSender> nl;
xrl.set_resolved_sender(nl);
if (send_resolved(xrl, dbe, ds->cb(), false) == false) {
// We tried to force sender to send xrl and it declined the
// opportunity. This should only happen when it's out of buffer
Expand Down Expand Up @@ -736,48 +701,6 @@ XrlRouter::finder_ready_event(const string& tgt_name)
}


// If this really doesn't work..then don't let anyone use it. Making
// it #if 0. --Ben

#if 0
//
// XXX This is unfinished code related to a batch XRL implementation.
// It is unfortunately incompatible, straight off, with using refcounts to
// manage XrlPFSender's lifecycle, so it needs to be revisited later by
// an interested party.
// Also, the overloading of the get_sender() method name is potentially
// confusing. --bms

void
XrlRouter::batch_start(const string& target)
{
XrlPFSender& sender = get_sender(target);

sender.batch_start();
}

void
XrlRouter::batch_stop(const string& target)
{
XrlPFSender& sender = get_sender(target);

sender.batch_stop();
}

ref_ptr<XrlPFSender>
XrlRouter::get_sender(const string& target)
{
XrlPFSender* s = 0;

SENDERS::iterator i = _senders2.find(target);
XLOG_ASSERT(i != _senders2.end());

s = i->second;

return s;
}
#endif

string XrlRouter::toString() const {
ostringstream oss;
if (_fac) {
Expand Down
17 changes: 2 additions & 15 deletions xorp/libxipc/xrl_router.hh
Expand Up @@ -34,10 +34,6 @@
#include "finder_constants.hh"
#include "finder_client_observer.hh"

#include <boost/shared_ptr.hpp>

using boost::shared_ptr;

class DispatchState;

class FinderClient;
Expand Down Expand Up @@ -219,11 +215,7 @@ protected:
uint16_t finder_port);

private:
// XXX
#if 0
XrlPFSender& get_sender(const string& target);
#endif
shared_ptr<XrlPFSender> lookup_sender(const Xrl& xrl, FinderDBEntry *dbe);
ref_ptr<XrlPFSender> lookup_sender(const Xrl& xrl, FinderDBEntry *dbe);

protected:
EventLoop& _e;
Expand All @@ -235,19 +227,14 @@ protected:

list<XrlPFListener*> _listeners; // listeners
list<XrlRouterDispatchState*> _dsl; // dispatch state
list< shared_ptr<XrlPFSender> > _senders; // active senders
list< ref_ptr<XrlPFSender> > _senders; // active senders

static uint32_t _icnt; // instance count

// XXX the following are mostly only used by the incomplete
// batch support. Stick to using unchecked pointers for now --bms
// TODO: That is just waiting for bugs to happen..fix this. --Ben
private:
typedef map<string, XI*> XIM;
typedef map<string, XrlPFSender* > SENDERS;

mutable XIM _xi_cache;
SENDERS _senders2;
};

/**
Expand Down
3 changes: 3 additions & 0 deletions xorp/libxorp/ref_ptr.hh
Expand Up @@ -228,6 +228,9 @@ public:
* necessary.
*/
void release() const { unref(); }
/* mimic functionality of boost weak_ptr, same as release()
*/
void reset() const { unref(); }

ref_ptr(_Tp* data, int32_t index) : _M_ptr(data), _M_index(index)
{
Expand Down

0 comments on commit 7fa28b3

Please sign in to comment.