[Modify] Lock it within the method

This commit is contained in:
sta 2016-04-03 16:33:18 +09:00
parent 40b74422a2
commit 655acc6528

View File

@ -469,16 +469,17 @@ namespace WebSocketSharp.Net
cleanup (force); cleanup (force);
} }
// Must be called with a lock on _ctxQueue.
private HttpListenerContext getContextFromQueue () private HttpListenerContext getContextFromQueue ()
{ {
if (_ctxQueue.Count == 0) lock (_ctxQueueSync) {
return null; if (_ctxQueue.Count == 0)
return null;
var ctx = _ctxQueue[0]; var ctx = _ctxQueue[0];
_ctxQueue.RemoveAt (0); _ctxQueue.RemoveAt (0);
return ctx; return ctx;
}
} }
private void sendServiceUnavailable () private void sendServiceUnavailable ()
@ -561,12 +562,10 @@ namespace WebSocketSharp.Net
// Lock _waitQueue early to avoid race conditions. // Lock _waitQueue early to avoid race conditions.
lock (_waitQueueSync) { lock (_waitQueueSync) {
lock (_ctxQueueSync) { var ctx = getContextFromQueue ();
var ctx = getContextFromQueue (); if (ctx != null) {
if (ctx != null) { asyncResult.Complete (ctx, true);
asyncResult.Complete (ctx, true); return asyncResult;
return asyncResult;
}
} }
_waitQueue.Add (asyncResult); _waitQueue.Add (asyncResult);