From e90c1533913c291e048b250ce3a65d6c21337aab Mon Sep 17 00:00:00 2001 From: sta Date: Sat, 16 Apr 2016 15:21:46 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/Net/HttpListener.cs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/websocket-sharp/Net/HttpListener.cs b/websocket-sharp/Net/HttpListener.cs index 7c25b287..22558b58 100644 --- a/websocket-sharp/Net/HttpListener.cs +++ b/websocket-sharp/Net/HttpListener.cs @@ -566,23 +566,21 @@ namespace WebSocketSharp.Net internal HttpListenerAsyncResult BeginGetContext (HttpListenerAsyncResult asyncResult) { - // Lock _ctxRegistrySync early to avoid race conditions. lock (_ctxRegistrySync) { if (!_listening) throw new HttpListenerException (995); - lock (_waitQueueSync) { - var ctx = getContextFromQueue (); - if (ctx != null) { - asyncResult.Complete (ctx, true); - return asyncResult; - } - - _waitQueue.Add (asyncResult); + var ctx = getContextFromQueue (); + if (ctx == null) { + lock (_waitQueueSync) + _waitQueue.Add (asyncResult); + } + else { + asyncResult.Complete (ctx, true); } - } - return asyncResult; + return asyncResult; + } } internal void CheckDisposed ()