Skip to content

Commit

Permalink
lock unreliable channel only if there is pending packets
Browse files Browse the repository at this point in the history
  • Loading branch information
RevenantX committed Aug 3, 2024
1 parent 5124524 commit 265487d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions LiteNetLib/NetPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,19 +1406,22 @@ internal void Update(float deltaTime)
_channelSendQueue.Enqueue(channel);
}
}

int unreliableCount;
lock (_unreliableChannelLock)

if (_unreliablePendingCount > 0)
{
(_unreliableChannel, _unreliableSecondQueue) = (_unreliableSecondQueue, _unreliableChannel);
unreliableCount = _unreliablePendingCount;
_unreliablePendingCount = 0;
}
for (int i = 0; i < unreliableCount; i++)
{
var packet = _unreliableSecondQueue[i];
SendUserData(packet);
NetManager.PoolRecycle(packet);
int unreliableCount;
lock (_unreliableChannelLock)
{
(_unreliableChannel, _unreliableSecondQueue) = (_unreliableSecondQueue, _unreliableChannel);
unreliableCount = _unreliablePendingCount;
_unreliablePendingCount = 0;
}
for (int i = 0; i < unreliableCount; i++)
{
var packet = _unreliableSecondQueue[i];
SendUserData(packet);
NetManager.PoolRecycle(packet);
}
}

SendMerged();
Expand Down

0 comments on commit 265487d

Please sign in to comment.