From d9458c20b78e2fb3b4fd997e87ec7ed15a4dadc3 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 22 Mar 2012 15:09:23 -0400 Subject: [PATCH] use the API enabled by alina's latest patch --- src/emu/model/emu-net-device.cc | 24 ++---------------------- src/emu/model/emu-net-device.h | 7 ------- src/tap-bridge/model/tap-bridge.cc | 23 +---------------------- src/tap-bridge/model/tap-bridge.h | 7 ------- 4 files changed, 3 insertions(+), 58 deletions(-) diff --git a/src/emu/model/emu-net-device.cc b/src/emu/model/emu-net-device.cc index 2635ad2c9..7108f0ceb 100644 --- a/src/emu/model/emu-net-device.cc +++ b/src/emu/model/emu-net-device.cc @@ -271,26 +271,6 @@ EmuNetDevice::StartDevice (void) NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Device is already started"); } - // - // We're going to need a pointer to the realtime simulator implementation. - // It's important to remember that access to that implementation may happen - // in a completely different thread than the simulator is running in (we're - // going to spin up that thread below). We are talking about multiple threads - // here, so it is very, very dangerous to do any kind of reference couning on - // a shared object that is unaware of what is happening. What we are going to - // do to address that is to get a reference to the realtime simulator here - // where we are running in the context of a running simulator scheduler -- - // recall we did a Simulator::Schedule of this method above. We get the - // simulator implementation pointer in a single-threaded way and save the - // underlying raw pointer for use by the (other) read thread. We must not - // free this pointer or we may delete the simulator out from under us an - // everyone else. We assume that the simulator implementation cannot be - // replaced while the emu device is running and so will remain valid through - // the time during which the read thread is running. - // - Ptr impl = DynamicCast (Simulator::GetImplementation ()); - m_rtImpl = GetPointer (impl); - // // A similar story exists for the node ID. We can't just naively do a // GetNode ()->GetId () since GetNode is going to give us a Ptr which @@ -823,8 +803,8 @@ EmuNetDevice::ReadThread (void) NS_LOG_INFO ("EmuNetDevice::EmuNetDevice(): Received packet on node " << m_nodeId); NS_LOG_INFO ("EmuNetDevice::ReadThread(): Scheduling handler"); - NS_ASSERT_MSG (m_rtImpl, "EmuNetDevice::ReadThread(): Realtime simulator implementation pointer not set"); - m_rtImpl->ScheduleRealtimeNowWithContext (m_nodeId, MakeEvent (&EmuNetDevice::ForwardUp, this, buf, len)); + Simulator::ScheduleWithContext (m_nodeId, Seconds (0.0), + MakeEvent (&EmuNetDevice::ForwardUp, this, buf, len)); buf = 0; } } diff --git a/src/emu/model/emu-net-device.h b/src/emu/model/emu-net-device.h index 36409082f..e2e34de44 100644 --- a/src/emu/model/emu-net-device.h +++ b/src/emu/model/emu-net-device.h @@ -33,7 +33,6 @@ #include "ns3/mac48-address.h" #include "ns3/system-thread.h" #include "ns3/system-mutex.h" -#include "ns3/realtime-simulator-impl.h" namespace ns3 { @@ -517,12 +516,6 @@ private: */ uint8_t *m_packetBuffer; - /** - * A copy of a raw pointer to the required real-time simulator implementation. - * Never free this pointer! - */ - RealtimeSimulatorImpl *m_rtImpl; - /* * a copy of the node id so the read thread doesn't have to GetNode() in * in order to find the node ID. Thread unsafe reference counting in diff --git a/src/tap-bridge/model/tap-bridge.cc b/src/tap-bridge/model/tap-bridge.cc index 98800f6a3..4c3c55d96 100644 --- a/src/tap-bridge/model/tap-bridge.cc +++ b/src/tap-bridge/model/tap-bridge.cc @@ -214,26 +214,6 @@ TapBridge::StartTapDevice (void) NS_ABORT_MSG_IF (m_sock != -1, "TapBridge::StartTapDevice(): Tap is already started"); - // - // We're going to need a pointer to the realtime simulator implementation. - // It's important to remember that access to that implementation may happen - // in a completely different thread than the simulator is running in (we're - // going to spin up that thread below). We are talking about multiple threads - // here, so it is very, very dangerous to do any kind of reference couning on - // a shared object that is unaware of what is happening. What we are going to - // do to address that is to get a reference to the realtime simulator here - // where we are running in the context of a running simulator scheduler -- - // recall we did a Simulator::Schedule of this method above. We get the - // simulator implementation pointer in a single-threaded way and save the - // underlying raw pointer for use by the (other) read thread. We must not - // free this pointer or we may delete the simulator out from under us an - // everyone else. We assume that the simulator implementation cannot be - // replaced while the tap bridge is running and so will remain valid through - // the time during which the read thread is running. - // - Ptr impl = DynamicCast (Simulator::GetImplementation ()); - m_rtImpl = GetPointer (impl); - // // A similar story exists for the node ID. We can't just naively do a // GetNode ()->GetId () since GetNode is going to give us a Ptr which @@ -684,8 +664,7 @@ TapBridge::ReadCallback (uint8_t *buf, ssize_t len) NS_LOG_INFO ("TapBridge::ReadCallback(): Received packet on node " << m_nodeId); NS_LOG_INFO ("TapBridge::ReadCallback(): Scheduling handler"); - NS_ASSERT_MSG (m_rtImpl, "TapBridge::ReadCallback(): Realtime simulator implementation pointer not set"); - m_rtImpl->ScheduleRealtimeNowWithContext (m_nodeId, MakeEvent (&TapBridge::ForwardToBridgedDevice, this, buf, len)); + Simulator::ScheduleWithContext (m_nodeId, Seconds (0.0), MakeEvent (&TapBridge::ForwardToBridgedDevice, this, buf, len)); } void diff --git a/src/tap-bridge/model/tap-bridge.h b/src/tap-bridge/model/tap-bridge.h index 2bfdc0198..cdc67e672 100644 --- a/src/tap-bridge/model/tap-bridge.h +++ b/src/tap-bridge/model/tap-bridge.h @@ -32,7 +32,6 @@ #include "ns3/ptr.h" #include "ns3/mac48-address.h" #include "ns3/unix-fd-reader.h" -#include "ns3/realtime-simulator-impl.h" namespace ns3 { @@ -458,12 +457,6 @@ private: */ uint8_t *m_packetBuffer; - /** - * A copy of a raw pointer to the required real-time simulator implementation. - * Never free this pointer! - */ - RealtimeSimulatorImpl *m_rtImpl; - /* * a copy of the node id so the read thread doesn't have to GetNode() in * in order to find the node ID. Thread unsafe reference counting in