mirror of
https://github.com/lubosz/overte.git
synced 2025-04-25 00:03:16 +02:00
Tweaking packet processing locking
This commit is contained in:
parent
d4d6f8f5d5
commit
4c200d75bc
2 changed files with 8 additions and 8 deletions
|
@ -23,7 +23,7 @@ void ReceivedPacketProcessor::queueReceivedPacket(const SharedNodePointer& sendi
|
|||
|
||||
NetworkPacket networkPacket(sendingNode, packet);
|
||||
lock();
|
||||
_packets.push_back(networkPacket);
|
||||
_queuedPackets.push_back(networkPacket);
|
||||
_nodePacketCounts[sendingNode->getUUID()]++;
|
||||
unlock();
|
||||
|
||||
|
@ -33,29 +33,28 @@ void ReceivedPacketProcessor::queueReceivedPacket(const SharedNodePointer& sendi
|
|||
|
||||
bool ReceivedPacketProcessor::process() {
|
||||
|
||||
if (_packets.size() == 0) {
|
||||
if (_queuedPackets.size() == 0) {
|
||||
_waitingOnPacketsMutex.lock();
|
||||
_hasPackets.wait(&_waitingOnPacketsMutex, getMaxWait());
|
||||
_waitingOnPacketsMutex.unlock();
|
||||
}
|
||||
|
||||
preProcess();
|
||||
QVector<NetworkPacket> currentPackets;
|
||||
if (!_packets.size()) {
|
||||
if (!_queuedPackets.size()) {
|
||||
return isStillRunning();
|
||||
}
|
||||
|
||||
lock();
|
||||
std::swap(currentPackets, _packets);
|
||||
_processingPackets.swap(_queuedPackets);
|
||||
unlock();
|
||||
|
||||
foreach(auto& packet, currentPackets) {
|
||||
foreach(auto& packet, _processingPackets) {
|
||||
processPacket(packet.getNode(), packet.getByteArray());
|
||||
midProcess();
|
||||
}
|
||||
|
||||
lock();
|
||||
foreach(auto& packet, currentPackets) {
|
||||
foreach(auto& packet, _processingPackets) {
|
||||
_nodePacketCounts[packet.getNode()->getUUID()]--;
|
||||
}
|
||||
unlock();
|
||||
|
|
|
@ -75,7 +75,8 @@ protected:
|
|||
|
||||
protected:
|
||||
|
||||
QVector<NetworkPacket> _packets;
|
||||
QVector<NetworkPacket> _queuedPackets;
|
||||
QVector<NetworkPacket> _processingPackets;
|
||||
QHash<QUuid, int> _nodePacketCounts;
|
||||
|
||||
QWaitCondition _hasPackets;
|
||||
|
|
Loading…
Reference in a new issue