1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-19 08:36:34 +09:00

Made CreateSenderChannel() reentrant

This commit is contained in:
lidgren
2012-02-09 14:56:42 +00:00
parent 66f4365103
commit 7be71a7873

View File

@@ -332,8 +332,20 @@ namespace Lidgren.Network
private NetSenderChannelBase CreateSenderChannel(NetMessageType tp) private NetSenderChannelBase CreateSenderChannel(NetMessageType tp)
{ {
NetSenderChannelBase chan; NetSenderChannelBase chan;
lock (m_sendChannels)
{
NetDeliveryMethod method = NetUtility.GetDeliveryMethod(tp); NetDeliveryMethod method = NetUtility.GetDeliveryMethod(tp);
int sequenceChannel = (int)tp - (int)method; int sequenceChannel = (int)tp - (int)method;
int channelSlot = (int)method - 1 + sequenceChannel;
if (m_sendChannels[channelSlot] != null)
{
// we were pre-empted by another call to this method
chan = m_sendChannels[channelSlot];
}
else
{
switch (method) switch (method)
{ {
case NetDeliveryMethod.Unreliable: case NetDeliveryMethod.Unreliable:
@@ -349,10 +361,9 @@ namespace Lidgren.Network
chan = new NetReliableSenderChannel(this, NetUtility.GetWindowSize(method)); chan = new NetReliableSenderChannel(this, NetUtility.GetWindowSize(method));
break; break;
} }
int channelSlot = (int)method - 1 + sequenceChannel;
NetException.Assert(m_sendChannels[channelSlot] == null);
m_sendChannels[channelSlot] = chan; m_sendChannels[channelSlot] = chan;
}
}
return chan; return chan;
} }