Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 17, 2010, 10:41:24 AM (15 years ago)
Author:
scheusso
Message:

network is now multithreaded again
further testing needed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network5/src/libraries/network/packet/Packet.cc

    r7759 r7772  
    3535#include <enet/enet.h>
    3636#include <boost/static_assert.hpp>
     37#include <boost/thread/mutex.hpp>
    3738
    3839#include "util/Debug.h"
     
    6162
    6263std::map<size_t, Packet *> Packet::packetMap_;
     64boost::mutex Packet::packetMapMutex_;
    6365
    6466Packet::Packet()
     
    142144      // Assures we don't create a packet and destroy it right after in another thread
    143145      // without having a reference in the packetMap_
     146      Packet::packetMapMutex_.lock();
    144147      packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
     148      Packet::packetMapMutex_.unlock();
    145149    }
    146150  }
     
    164168//  ENetPacket *temp = enetPacket_;
    165169//  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
    166   if(!Host::addPacket( enetPacket_, clientID_))
    167     enet_packet_destroy(this->enetPacket_); // if we could not add the packet to the enet queue delete it manually
     170  if( this->flags_ & PacketFlag::Reliable )
     171    Host::addPacket( enetPacket_, clientID_, 0);
     172  else
     173    Host::addPacket( enetPacket_, clientID_, 0);
    168174  return true;
    169175}
     
    228234void Packet::deletePacket(ENetPacket *enetPacket){
    229235  // Get our Packet from a global map with all Packets created in the send() method of Packet.
     236  Packet::packetMapMutex_.lock();
    230237  std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket));
    231238  assert(it != packetMap_.end());
     
    234241  delete it->second;
    235242  packetMap_.erase(it);
     243  Packet::packetMapMutex_.unlock();
    236244//   COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
    237245}
Note: See TracChangeset for help on using the changeset viewer.