Changeset 2171 for code/trunk/src/network/packet/Packet.cc
- Timestamp:
- Nov 10, 2008, 12:05:03 AM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/objecthierarchy merged: 2111-2115,2123,2132-2134,2143-2144,2153-2158,2160-2169
- Property svn:mergeinfo changed
-
code/trunk/src/network/packet/Packet.cc
r2087 r2171 46 46 #include "core/CoreIncludes.h" 47 47 48 namespace network{48 namespace orxonox{ 49 49 50 50 namespace packet{ … … 53 53 #define _PACKETID 0 54 54 55 std::map<ENetPacket *, Packet *> Packet::packetMap_; 55 std::map<size_t, Packet *> Packet::packetMap_; 56 boost::recursive_mutex Packet::packetMap_mutex; 56 57 57 58 Packet::Packet(){ … … 128 129 return false; 129 130 } 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); 130 134 // We deliver ENet the data address so that it doesn't memcpy everything again. 131 135 // --> We have to delete data_ ourselves! … … 134 138 // Add the packet to a global list so we can access it again once enet calls our 135 139 // 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; 137 141 } 138 142 #ifndef NDEBUG … … 153 157 // ENetPacket *temp = enetPacket_; 154 158 // 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_); 156 160 return true; 157 161 } … … 207 211 */ 208 212 void Packet::deletePacket(ENetPacket *enetPacket){ 213 boost::recursive_mutex::scoped_lock lock(Packet::packetMap_mutex); 209 214 // 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); 211 216 assert(it != packetMap_.end()); 212 217 // Make sure we don't delete it again in the destructor 213 218 it->second->enetPacket_ = 0; 214 219 delete it->second; 215 //packetMap_.erase(it);220 packetMap_.erase(it); 216 221 COUT(4) << "PacketMap size: " << packetMap_.size() << std::endl; 217 222 } … … 219 224 } // namespace packet 220 225 221 } // namespace network222 226 } // namespace orxonox 227
Note: See TracChangeset
for help on using the changeset viewer.