Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 10, 2008, 12:05:03 AM (15 years ago)
Author:
landauf
Message:

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/network/packet/Packet.cc

    r2087 r2171  
    4646#include "core/CoreIncludes.h"
    4747
    48 namespace network{
     48namespace orxonox{
    4949
    5050namespace packet{
     
    5353#define _PACKETID           0
    5454
    55 std::map<ENetPacket *, Packet *> Packet::packetMap_;
     55std::map<size_t, Packet *> Packet::packetMap_;
     56boost::recursive_mutex Packet::packetMap_mutex;
    5657
    5758Packet::Packet(){
     
    128129      return false;
    129130    }
     131    // Assures we don't create a packet and destroy it right after in another thread
     132    // without having a reference in the packetMap_
     133    boost::recursive_mutex::scoped_lock lock(Packet::packetMap_mutex);
    130134    // We deliver ENet the data address so that it doesn't memcpy everything again.
    131135    // --> We have to delete data_ ourselves!
     
    134138    // Add the packet to a global list so we can access it again once enet calls our
    135139    // deletePacket method. We can of course only give a one argument function to the ENet C library.
    136     packetMap_[enetPacket_] = this;
     140    packetMap_[(size_t)(void*)enetPacket_] = this;
    137141  }
    138142#ifndef NDEBUG
     
    153157//  ENetPacket *temp = enetPacket_;
    154158//  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
    155   network::Host::addPacket( enetPacket_, clientID_);
     159  Host::addPacket( enetPacket_, clientID_);
    156160  return true;
    157161}
     
    207211*/
    208212void Packet::deletePacket(ENetPacket *enetPacket){
     213  boost::recursive_mutex::scoped_lock lock(Packet::packetMap_mutex);
    209214  // Get our Packet from a gloabal map with all Packets created in the send() method of Packet.
    210   std::map<ENetPacket*, Packet*>::iterator it = packetMap_.find(enetPacket);
     215  std::map<size_t, Packet*>::iterator it = packetMap_.find((size_t)enetPacket);
    211216  assert(it != packetMap_.end());
    212217  // Make sure we don't delete it again in the destructor
    213218  it->second->enetPacket_ = 0;
    214219  delete it->second;
    215   //packetMap_.erase(it);
     220  packetMap_.erase(it);
    216221  COUT(4) << "PacketMap size: " << packetMap_.size() << std::endl;
    217222}
     
    219224} // namespace packet
    220225
    221 } // namespace network
    222 
     226} // namespace orxonox
     227
Note: See TracChangeset for help on using the changeset viewer.