mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-28 07:00:59 +03:00
Changed Monitor.TryEnter(...) to lock(...) {}
This commit is contained in:
@@ -163,25 +163,24 @@ namespace Amib.Threading.Internal
|
|||||||
int millisecondsTimeout,
|
int millisecondsTimeout,
|
||||||
WaitHandle cancelEvent)
|
WaitHandle cancelEvent)
|
||||||
{
|
{
|
||||||
// This method cause the caller to wait for a work item.
|
// This method cause the caller to wait for a work item.
|
||||||
// If there is at least one waiting work item then the
|
// If there is at least one waiting work item then the
|
||||||
// method returns immidiately with it.
|
// method returns immidiately with it.
|
||||||
//
|
//
|
||||||
// If there are no waiting work items then the caller
|
// If there are no waiting work items then the caller
|
||||||
// is queued between other waiters for a work item to arrive.
|
// is queued between other waiters for a work item to arrive.
|
||||||
//
|
//
|
||||||
// If a work item didn't come within millisecondsTimeout or
|
// If a work item didn't come within millisecondsTimeout or
|
||||||
// the user canceled the wait by signaling the cancelEvent
|
// the user canceled the wait by signaling the cancelEvent
|
||||||
// then the method returns null to indicate that the caller
|
// then the method returns null to indicate that the caller
|
||||||
// didn't get a work item.
|
// didn't get a work item.
|
||||||
|
|
||||||
WaiterEntry waiterEntry;
|
WaiterEntry waiterEntry;
|
||||||
WorkItem workItem = null;
|
WorkItem workItem = null;
|
||||||
|
|
||||||
try
|
lock (this)
|
||||||
{
|
{
|
||||||
while (!Monitor.TryEnter(this)) { }
|
//Stopwatch stopwatch = Stopwatch.StartNew();
|
||||||
//Stopwatch stopwatch = Stopwatch.StartNew();
|
|
||||||
//Monitor.Enter(this);
|
//Monitor.Enter(this);
|
||||||
//stopwatch.Stop();
|
//stopwatch.Stop();
|
||||||
|
|
||||||
@@ -202,10 +201,6 @@ namespace Amib.Threading.Internal
|
|||||||
// Put the waiter with the other waiters
|
// Put the waiter with the other waiters
|
||||||
PushWaiter(waiterEntry);
|
PushWaiter(waiterEntry);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
Monitor.Exit(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare array of wait handle for the WaitHandle.WaitAny()
|
// Prepare array of wait handle for the WaitHandle.WaitAny()
|
||||||
WaitHandle [] waitHandles = new WaitHandle[] {
|
WaitHandle [] waitHandles = new WaitHandle[] {
|
||||||
|
|||||||
Reference in New Issue
Block a user