From 547a9b6e1389447ea7d9d66a5c5a00ca96c14f7b Mon Sep 17 00:00:00 2001 From: Shih-Ying Hsu Date: Wed, 5 Mar 2014 11:49:17 -0800 Subject: [PATCH] Added validation and documentations for AwaitableThrottle.MaxConcurrent --- .../AwaitableThrottle.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.WebListener/AwaitableThrottle.cs b/src/Microsoft.AspNet.Server.WebListener/AwaitableThrottle.cs index 28e12028be..1a196b10c3 100644 --- a/src/Microsoft.AspNet.Server.WebListener/AwaitableThrottle.cs +++ b/src/Microsoft.AspNet.Server.WebListener/AwaitableThrottle.cs @@ -5,6 +5,7 @@ //------------------------------------------------------------------------------ using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using System.Threading.Tasks; @@ -39,7 +40,13 @@ namespace Microsoft.AspNet.Server.WebListener } set { - // Note: non-thread safe + Contract.Assert(_maxConcurrent >= 0, + "Behavior of this class is undefined for negative value"); + // Note: + // 1. This setter is non-thread safe. We assumed it doesnt need to be for simplicity sake. + // 2. Behavior of this class is not well defined if a negative value is passed in. If it + // is awaited before any Release() is called, the subsequent Relese() would eagerly + // unblock awaiting thread instead of waiting for _count to reach the negative value specified. _maxConcurrent = value; } }