This commit is contained in:
Gustavo J. A. M. Carneiro
2007-10-02 11:11:27 +01:00
3 changed files with 34 additions and 9 deletions

View File

@@ -78,16 +78,15 @@ void PacketSink::StartApplication() // Called at time specified by Start
m_socket = socketFactory->CreateSocket ();
m_socket->Bind (m_local);
}
m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
const Address &>) MakeCallback(&PacketSink::Receive, this));
m_socket->SetRecvCallback (MakeCallback(&PacketSink::Receive, this));
}
void PacketSink::StopApplication() // Called at time specified by Stop
{
if (!m_socket)
{
m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
const Address &>) NULL);
m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket>,
const Packet &, const Address &> ());
}
}

View File

@@ -192,7 +192,7 @@ Object::~Object ()
Ptr<Object>
Object::DoQueryInterface (InterfaceId iid) const
{
NS_ASSERT (Check ());
NS_ASSERT (CheckLoose ());
const Object *currentObject = this;
do {
NS_ASSERT (currentObject != 0);
@@ -227,24 +227,26 @@ Object::AddInterface (Ptr<Object> o)
{
NS_ASSERT (!m_disposed);
NS_ASSERT (!o->m_disposed);
NS_ASSERT (Check ());
NS_ASSERT (o->Check ());
NS_ASSERT (CheckLoose ());
NS_ASSERT (o->CheckLoose ());
Object *other = PeekPointer (o);
Object *next = m_next;
m_next = other->m_next;
other->m_next = next;
NS_ASSERT (Check ());
NS_ASSERT (o->Check ());
NS_ASSERT (CheckLoose ());
NS_ASSERT (o->CheckLoose ());
}
void
Object::TraceConnect (std::string path, const CallbackBase &cb) const
{
NS_ASSERT (CheckLoose ());
GetTraceResolver ()->Connect (path, cb, TraceContext ());
}
void
Object::TraceDisconnect (std::string path, const CallbackBase &cb) const
{
NS_ASSERT (CheckLoose ());
GetTraceResolver ()->Disconnect (path, cb);
}
@@ -264,6 +266,7 @@ Object::DoDispose (void)
Ptr<TraceResolver>
Object::GetTraceResolver (void) const
{
NS_ASSERT (CheckLoose ());
Ptr<InterfaceIdTraceResolver> resolver =
Create<InterfaceIdTraceResolver> (this);
return resolver;
@@ -275,6 +278,28 @@ Object::Check (void) const
return (m_count > 0);
}
/* In some cases, when an event is scheduled against a subclass of
* Object, and if no one owns a reference directly to this object, the
* object is alive, has a refcount of zero and the method ran when the
* event expires runs against the raw pointer which means that we are
* manipulating an object with a refcount of zero. So, instead we
* check the aggregate reference count.
*/
bool
Object::CheckLoose (void) const
{
uint32_t refcount = 0;
const Object *current = this;
do
{
refcount += current->m_count;
current = current->m_next;
}
while (current != this);
return (refcount > 0);
}
void
Object::MaybeDelete (void) const
{

View File

@@ -186,6 +186,7 @@ private:
TraceResolver::SourceCollection *collection) const;
void DoTraceAll (std::ostream &os, const TraceContext &context) const;
bool Check (void) const;
bool CheckLoose (void) const;
void MaybeDelete (void) const;
mutable uint32_t m_count;
InterfaceId m_iid;