Skip to content

Commit

Permalink
Reorder members to force correct distruction order. ORDER IS IMPORTANT!
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian Köstler authored and koalo committed Jan 16, 2017
1 parent 2870bab commit 79cfc56
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 71 deletions.
2 changes: 1 addition & 1 deletion examples/common/traffic/TrafficEvaluation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ TrafficEvaluation::TrafficEvaluation(uint8_t msgSize,

TrafficEvaluation::~TrafficEvaluation() {
if(frame) {
frame.deleteObject();
frame.delete_object();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/communication/base/DataIndication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DataIndication::DataIndication(AirframePtr frame, node_t src, node_t dst) :

DataIndication::~DataIndication() {
if (frame) {
frame.deleteObject();
frame.delete_object();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/communication/base/DataRequestResponse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ DataRequest::DataRequest(node_t dst, AirframePtr frame,

DataRequest::~DataRequest() {
if (this->frame) {
this->frame.deleteObject();
this->frame.delete_object();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/communication/base/RemoteModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class RemoteModule: public Module {
#endif
RemoteMethod *method = remoteFindMethod(name);
if (method == NULL) {
frame.deleteObject();
frame.delete_object();
}

return method->invoke(frame);
Expand Down
2 changes: 1 addition & 1 deletion src/communication/dsme/DSMEMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class DSMEMessage : public IDSMEMessage ADDITIONAL_CLASS {

virtual ~DSMEMessage() override {
if (frame) {
frame.deleteObject();
frame.delete_object();
}

if (request != nullptr) {
Expand Down
4 changes: 2 additions & 2 deletions src/communication/dsme/DSMEPlatformBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class DSMEPlatformBase : public cometos::MacAbstractionLayer, public IDSMEPlatfo
PHY_PIB phy_pib;
MAC_PIB mac_pib;

DSMEMessageBuffer messageBuffer;

DSMELayer dsme;

mcps_sap::MCPS_SAP mcps_sap;
Expand All @@ -144,8 +146,6 @@ class DSMEPlatformBase : public cometos::MacAbstractionLayer, public IDSMEPlatfo
cometos::Message* ccaTimer;
Delegate<void(bool)> txEndCallback;

DSMEMessageBuffer messageBuffer;

/** @brief the bit rate at which we transmit */
double bitrate;

Expand Down
4 changes: 2 additions & 2 deletions src/communication/dsme/helper/DSMEMessageBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ DSMEMessageBuffer::~DSMEMessageBuffer() {
AirframePtr p = airframeStack.top();
airframeStack.top().reset();
airframeStack.pop();
p.deleteObject();
p.delete_object();
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ void DSMEMessageBuffer::release(DSMEMessage* message) {
ASSERT(result);
}
else if(frame) {
frame.deleteObject(); // the stack is full anyway
frame.delete_object(); // the stack is full anyway
}
}
palExec_atomicEnd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ fsmReturnStatus MacAbstractionLayer::stateCCA(MacEvent& e) {

txPkt->removeAll(); // remove all meta data

MacPacket *macPkt = new MacPacket();
checked_ptr<MacPacket> macPkt = make_checked<MacPacket>();
macPkt->encapsulateArray(txPkt->getData(), txPkt->getLength());

// possibly need meta data for empirical physical layer
Expand All @@ -428,11 +428,10 @@ fsmReturnStatus MacAbstractionLayer::stateCCA(MacEvent& e) {
// now use the more realistic RX-TX switch time (during which
// the RadioStateAnalougeModel should set the attenuation factor to
// 0.0 (meaning the incoming signal has a power of 0 Watt)
attachSignal(macPkt, simTime() + switchTime, currTxPower);
sendDelayed(macPkt, switchTime, lowerGateOut);
attachSignal(macPkt.get(), simTime() + switchTime, currTxPower);
sendDelayed(macPkt.decapsulate(), switchTime, lowerGateOut);

return transition(&MacAbstractionLayer::stateTransmitFrame);

}
}
// receiving frame during cca
Expand Down Expand Up @@ -642,7 +641,7 @@ void MacAbstractionLayer::receiveLowerControl(cMessage *msg) {
dispatch(e);
} else if (msg->getKind() == BaseDecider::PACKET_DROPPED) {
//ASSERT(phy->getRadioState() == Radio::RX);
MacPacket *pktMac = check_and_cast<MacPacket*>(msg);
checked_ptr<MacPacket> pktMac(check_and_cast<MacPacket*>(msg));
AirframePtr pkt = pktMac->decapsulateNewAirframe();

MacHeader header;
Expand All @@ -664,7 +663,7 @@ void MacAbstractionLayer::receiveLowerControl(cMessage *msg) {
handleRxDrop("ack", header.src, header.dst, dre, ackFrames);
}
}
pkt.deleteObject();
pkt.delete_object();

// we additionally dispatch a frame dropped event to handle a situation
// in which we waited with TX for RX of a frame which then failed --
Expand Down Expand Up @@ -729,7 +728,7 @@ void MacAbstractionLayer::handleDataFromLower(
<< header.dst << " nwkId="
<< (int) header.dstNwkId
<< " supprRxWhileTx=" <<suppressRxWhileTxPending)
pkt.deleteObject();
pkt.delete_object();
if (phy->getChannelState().isIdle()) {
MacEvent e(MacEvent::EXPECTED_FRAME_DROPPED);
dispatch(e);
Expand All @@ -743,7 +742,7 @@ void MacAbstractionLayer::handleDataFromLower(

if (!promiscuousMode && (filterByAddr || filterByNetwork)) {
LOG_INFO("DISCARD data from " << cometos::hex << header.src << " to " << header.dst << " nwkId=" << (int) header.dstNwkId);
pkt.deleteObject();
pkt.delete_object();

// signal that a frame was received but dropped due to filtering
if (phy->getChannelState().isIdle()) {
Expand Down Expand Up @@ -794,18 +793,18 @@ void MacAbstractionLayer::handleDataFromLower(
}

ASSERT(switchTime.dbl() >= 0);
MacPacket* macPkt = new MacPacket();
checked_ptr<MacPacket> macPkt = make_checked<MacPacket>();
macPkt->encapsulateArray(ack->getData(), ack->getLength());

// possibly need meta data for empirical physical layer
// TODO quite dirty hack --- better solution?
macPkt->meta.set(new NodeId(getId()));
ack.deleteObject();
ack.delete_object();

attachSignal(macPkt, simTime() + aTurnaroundTime, txPower);
attachSignal(macPkt.get(), simTime() + aTurnaroundTime, txPower);

LOG_INFO("send ack of size" << " omnetppLen=" << macPkt->getByteLength());
sendDelayed(macPkt, aTurnaroundTime, lowerGateOut);
sendDelayed(macPkt.decapsulate(), aTurnaroundTime, lowerGateOut);
MacEvent e(MacEvent::ACKED_FRAME_RECEIVED);
dispatch(e);
}
Expand Down Expand Up @@ -835,7 +834,7 @@ void MacAbstractionLayer::handleDataFromLower(
void MacAbstractionLayer::receiveLowerData(cMessage *msg) {

// Get data from Mac Packet
MacPacket *pktMac = check_and_cast<MacPacket*>(msg);
checked_ptr<MacPacket> pktMac(check_and_cast<MacPacket*>(msg));
AirframePtr pkt = pktMac->decapsulateNewAirframe();
PhyToMacControlInfo* cinfo =
check_and_cast<PhyToMacControlInfo*>(pktMac->getControlInfo());
Expand Down Expand Up @@ -875,22 +874,21 @@ void MacAbstractionLayer::receiveLowerData(cMessage *msg) {
handleDataFromLower(header, pkt, dre, lqi, lqiValid, rssi);
} else if (header.type == MAC_TYPE_ACK) {
handleAckFromLower(rssi, header, dre);
pkt.deleteObject();
pkt.delete_object();
} else {
pkt.deleteObject();
pkt.delete_object();
// invalid packet
ASSERT(false);
}

// do not delete earlier, as we pass dre, which is a pointer into cinfo, which
// is a pointer into pktMac, to the handleData/handleAck methods just above
delete pktMac;
pktMac = NULL;
pktMac.delete_object();
}

void MacAbstractionLayer::rxEnd(AirframePtr pkt, node_t src, node_t dst, MacRxInfo const & info) {
LOG_ERROR("Discrd data");ASSERT(false);
pkt.deleteObject();
pkt.delete_object();
// should be implemented by derived class
}

Expand Down Expand Up @@ -948,21 +946,21 @@ void MacAbstractionLayer::timeout(Message *msg) {
bool MacAbstractionLayer::sendAirframe(AirframePtr frame, node_t dst, uint8_t mode, const ObjectContainer* meta) {
if (failure == true) {
LOG_DEBUG("MAC in fail Mode");
frame.deleteObject();
frame.delete_object();
return false;
}

// discard frames send to our own address
if (dst == palId_id()) {
LOG_WARN("discarded frame to this node's address")
frame.deleteObject();
frame.delete_object();
return false;
}

mac_networkId_t dstNwk = nwkId;;

if (txPkt) {
frame.deleteObject();
frame.delete_object();
LOG_DEBUG("abort: currently sending");ASSERT(false);
return false;
}
Expand Down Expand Up @@ -1002,7 +1000,7 @@ bool MacAbstractionLayer::sendToNetwork(AirframePtr frame, node_t dst,
LOG_DEBUG("sending pckt");

if (enable == false) {
frame.deleteObject();
frame.delete_object();
return false;
}

Expand Down Expand Up @@ -1100,7 +1098,7 @@ void MacAbstractionLayer::txDone(macTxResult_t result) {
// make sure that ackRssi is only set to valid directly after receiving ACK
ackRssi = RSSI_INVALID;

txPkt.deleteObject();
txPkt.delete_object();

if (result == MTR_SUCCESS)
sendingSucceed++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void MacInterfTest::finish() {
void MacInterfTest::rxEnd(cometos::AirframePtr frame, node_t src, node_t dst, cometos::MacRxInfo const & info) {
uint8_t r;
(*frame) >> r;
frame.deleteObject();
frame.delete_object();
if (getId() != 0 || row != 0) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/communication/ieee802154/mac/omnetpp/mixim/MacPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "Airframe.h"
#include "ObjectContainer.h"
#include "Memory.h"

/*PROTOTYPES-----------------------------------------------------------------*/

Expand All @@ -59,7 +60,7 @@ class MacPacket: public omnetpp::cPacket {

MacPacket(const MacPacket& other);

virtual MacPacket *dup() const {
virtual MacPacket* dup() const override {
return new MacPacket(*this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/communication/ieee802154/phy/EmpiricDecider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ Mapping* EmpiricDecider::createConstantMapping(simtime_t start, simtime_t end,

LinkStats EmpiricDecider::getLinkStatsForFrame(AirFrame* frame) {
LinkStats stats;
cometos::MacPacket* mac = check_and_cast<cometos::MacPacket*> (frame->getEncapsulatedPacket());
cometos::checked_ptr<cometos::MacPacket> mac(check_and_cast<cometos::MacPacket*> (frame->getEncapsulatedPacket()));
if (!mac->meta.has<cometos::NodeId>()) {
ASSERT(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/communication/ipv6/lowpan/LowpanAdaptionLayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ void LowpanAdaptionLayer::handleMACIndication(LowpanIndication *ind) {
}

delete ind;
frame.deleteObject();
frame.delete_object();
}


Expand Down
18 changes: 17 additions & 1 deletion src/core/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ class checked_ptr {
}
}

T* decapsulate() {
if(this->wrapped_object) {
ASSERT(unique());

T* temp = this->wrapped_object->raw_instance;

this->wrapped_object->raw_instance = nullptr;
delete this->wrapped_object;
this->wrapped_object = nullptr;

return temp;
} else {
return nullptr;
}
}

T& operator*() {
ASSERT(this->wrapped_object != nullptr);
ASSERT(this->wrapped_object->raw_instance != nullptr);
Expand Down Expand Up @@ -177,7 +193,7 @@ class checked_ptr {
return use_count() == 1;
}

void deleteObject() {
void delete_object() {
ASSERT(unique());

if(this->wrapped_object) {
Expand Down
10 changes: 5 additions & 5 deletions src/files/deluge/Deluge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ fsmReturnStatus Deluge::handleSummary() {
uint8_t gamma;
(*frame) >> versionNumber;
(*frame) >> gamma;
frame.deleteObject();
frame.delete_object();

#ifdef DELUGE_OUTPUT
getCout() << "[" << palId_id() << "] " << __PRETTY_FUNCTION__ << ": Received summary (v=" << versionNumber << ",g=" << static_cast<uint16_t>(gamma) << ")" << endl;
Expand Down Expand Up @@ -502,7 +502,7 @@ void Deluge::handleObjectProfile() {
mActive = true;
}
}
frame.deleteObject();
frame.delete_object();
}

fsmReturnStatus Deluge::handlePageRequest() {
Expand All @@ -511,7 +511,7 @@ fsmReturnStatus Deluge::handlePageRequest() {
AirframePtr frame = rcvdMsg->decapsulateAirframe();
(*frame) >> requestedPage;
(*frame) >> requestedPackets;
frame.deleteObject();
frame.delete_object();

// Check availability of page
uint8_t gamma = pInfo->getHighestCompletePage();
Expand Down Expand Up @@ -629,7 +629,7 @@ void Deluge::handlePacket() {
(*frame) >> packet;
(*frame) >> crc;
(*frame) >> this->mBuffer;
frame.deleteObject();
frame.delete_object();

if (page != this->mPageRX) {
#ifdef DELUGE_OUTPUT
Expand Down Expand Up @@ -844,7 +844,7 @@ void Deluge::handlePageRequestTX() {
uint32_t requestedPackets;
(*frame) >> requestedPage;
(*frame) >> requestedPackets;
frame.deleteObject();
frame.delete_object();

if(mPageTX == requestedPage) {
mRequestedPackets |= requestedPackets;
Expand Down

0 comments on commit 79cfc56

Please sign in to comment.