mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:43:50 +02:00
Merge pull request #5242 from jherico/packet_processing
Eliminate per-packet locking for processing
This commit is contained in:
commit
b4f04af66f
1 changed files with 19 additions and 10 deletions
|
@ -38,19 +38,28 @@ bool ReceivedPacketProcessor::process() {
|
|||
_hasPackets.wait(&_waitingOnPacketsMutex, getMaxWait());
|
||||
_waitingOnPacketsMutex.unlock();
|
||||
}
|
||||
|
||||
preProcess();
|
||||
while (_packets.size() > 0) {
|
||||
lock(); // lock to make sure nothing changes on us
|
||||
NetworkPacket& packet = _packets.front(); // get the oldest packet
|
||||
NetworkPacket temporary = packet; // make a copy of the packet in case the vector is resized on us
|
||||
_packets.erase(_packets.begin()); // remove the oldest packet
|
||||
if (!temporary.getNode().isNull()) {
|
||||
_nodePacketCounts[temporary.getNode()->getUUID()]--;
|
||||
}
|
||||
unlock(); // let others add to the packets
|
||||
processPacket(temporary.getNode(), temporary.getByteArray()); // process our temporary copy
|
||||
if (!_packets.size()) {
|
||||
return isStillRunning();
|
||||
}
|
||||
|
||||
lock();
|
||||
QVector<NetworkPacket> currentPackets;
|
||||
currentPackets.swap(_packets);
|
||||
unlock();
|
||||
|
||||
foreach(auto& packet, currentPackets) {
|
||||
processPacket(packet.getNode(), packet.getByteArray());
|
||||
midProcess();
|
||||
}
|
||||
|
||||
lock();
|
||||
foreach(auto& packet, currentPackets) {
|
||||
_nodePacketCounts[packet.getNode()->getUUID()]--;
|
||||
}
|
||||
unlock();
|
||||
|
||||
postProcess();
|
||||
return isStillRunning(); // keep running till they terminate us
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue