From 4b16bf08cebf5acb44de78737de3b4ce3eedd777 Mon Sep 17 00:00:00 2001 From: Michal Staszewski Date: Tue, 21 Jun 2011 14:44:04 +0200 Subject: [PATCH] CHG: passive wait on DequeueWorkItem (cherry picked from commit ac49cc8dce0519e29f26cacc5e785134300c6639) --- SmartThreadPool/WorkItemsQueue.cs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/SmartThreadPool/WorkItemsQueue.cs b/SmartThreadPool/WorkItemsQueue.cs index e7e265a..689044a 100644 --- a/SmartThreadPool/WorkItemsQueue.cs +++ b/SmartThreadPool/WorkItemsQueue.cs @@ -177,14 +177,8 @@ namespace Amib.Threading.Internal WaiterEntry waiterEntry; WorkItem workItem = null; - - try - { - while (!Monitor.TryEnter(this)) { } - //Stopwatch stopwatch = Stopwatch.StartNew(); - //Monitor.Enter(this); - //stopwatch.Stop(); - + lock (this) + { ValidateNotDisposed(); // If there are waiting work items then take one and return. @@ -201,11 +195,7 @@ namespace Amib.Threading.Internal // Put the waiter with the other waiters PushWaiter(waiterEntry); - } - finally - { - Monitor.Exit(this); - } + } // Prepare array of wait handle for the WaitHandle.WaitAny() WaitHandle [] waitHandles = new WaitHandle[] {