private const int ID_DISABLED_AND_ANONYMOUS_OWNED = unchecked((int)0x80000001); //1000 0000 0000 0000 0000 0000 0000 0001
// If the thread is unowned if:
- // m_owner zero and the threa tracking is enabled
+ // m_owner zero and the thread tracking is enabled
// m_owner & LOCK_ANONYMOUS_OWNED = zero and the thread tracking is disabled
private const int LOCK_UNOWNED = 0;
// In this case there are three ways to acquire the lock
// 1- the first way the thread either tries to get the lock if it's free or updates the waiters, if the turn >= the processors count then go to 3 else go to 2
// 2- In this step the waiter threads spins and tries to acquire the lock, the number of spin iterations and spin count is dependent on the thread turn
- // the late the thread arrives the more it spins and less frequent it check the lock avilability
+ // the late the thread arrives the more it spins and less frequent it check the lock availability
// Also the spins count is increases each iteration
// If the spins iterations finished and failed to acquire the lock, go to step 3
// 3- This is the yielding step, there are two ways of yielding Thread.Yield and Sleep(1)
{
if (CompareExchange(ref m_owner, observedOwner | 1, observedOwner, ref lockTaken) == observedOwner)
{
- // Aquired lock
+ // Acquired lock
return;
}
if (millisecondsTimeout == 0)
{
- // Did not aquire lock in CompareExchange and timeout is 0 so fail fast
+ // Did not acquire lock in CompareExchange and timeout is 0 so fail fast
return;
}
}
else if (millisecondsTimeout == 0)
{
- // Did not aquire lock as owned and timeout is 0 so fail fast
+ // Did not acquire lock as owned and timeout is 0 so fail fast
return;
}
else //failed to acquire the lock,then try to update the waiters. If the waiters count reached the maximum, jsut break the loop to avoid overflow
if ((observedOwner & LOCK_ANONYMOUS_OWNED) == LOCK_UNOWNED)
{
int newOwner = (observedOwner & WAITERS_MASK) == 0 ? // Gets the number of waiters, if zero
- observedOwner | 1 // don't decrement it. just set the lock bit, it is zzero because a previous call of Exit(false) ehich corrupted the waiters
+ observedOwner | 1 // don't decrement it. just set the lock bit, it is zero because a previous call of Exit(false) which corrupted the waiters
: (observedOwner - 2) | 1; // otherwise decrement the waiters and set the lock bit
Debug.Assert((newOwner & WAITERS_MASK) >= 0);
/// </exception>
public void Exit(bool useMemoryBarrier)
{
- // This is the fast path for the thread tracking is diabled and not to use memory barrier, otherwise go to the slow path
- // The reason not to add else statement if the usememorybarrier is that it will add more barnching in the code and will prevent
+ // This is the fast path for the thread tracking is disabled and not to use memory barrier, otherwise go to the slow path
+ // The reason not to add else statement if the usememorybarrier is that it will add more branching in the code and will prevent
// method inlining, so this is optimized for useMemoryBarrier=false and Exit() overload optimized for useMemoryBarrier=true.
int tmpOwner = m_owner;
if ((tmpOwner & LOCK_ID_DISABLE_MASK) != 0 & !useMemoryBarrier)
IntPtr thread = DONT_USE_InternalThread;
// This should never happen under normal circumstances. m_assembly is always assigned before it is handed out to the user.
- // There are ways how to create an unitialized objects through remoting, etc. Avoid AVing in the EE by throwing a nice
+ // There are ways how to create an uninitialized objects through remoting, etc. Avoid AVing in the EE by throwing a nice
// exception here.
if (thread == IntPtr.Zero)
throw new ArgumentException(null, SR.Argument_InvalidHandle);
if (m_Delegate != null)
{
// If we reach here with a null delegate, something is broken. But we'll let the StartInternal method take care of
- // reporting an error. Just make sure we dont try to dereference a null delegate.
+ // reporting an error. Just make sure we don't try to dereference a null delegate.
ThreadHelper t = (ThreadHelper)(m_Delegate.Target);
ExecutionContext ec = ExecutionContext.Capture();
t.SetExecutionContextHelper(ec);
/*=========================================================================
** Suspends the current thread for timeout milliseconds. If timeout == 0,
- ** forces the thread to give up the remainer of its timeslice. If timeout
+ ** forces the thread to give up the remainder of its timeslice. If timeout
** == Timeout.Infinite, no timeout will occur.
**
** Exceptions: ArgumentException if timeout < 0.
}
- /* wait for a length of time proportial to 'iterations'. Each iteration is should
+ /* wait for a length of time proportional to 'iterations'. Each iteration is should
only take a few machine instructions. Calling this API is preferable to coding
- a explict busy loop because the hardware can be informed that it is busy waiting. */
+ a explicit busy loop because the hardware can be informed that it is busy waiting. */
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void SpinWaitInternal(int iterations);
} // End of class Thread
// declaring a local var of this enum type and passing it by ref into a function that needs to do a
- // stack crawl will both prevent inlining of the calle and pass an ESP point to stack crawl to
+ // stack crawl will both prevent inlining of the callee and pass an ESP point to stack crawl to
// Declaring these in EH clauses is illegal; they must declared in the main method body
internal enum StackCrawlMark
{
// And then check to see if we can fix up the indexes (if we're at
// the edge). If we can't, we just leave nulls in the array and they'll
- // get filtered out eventually (but may lead to superflous resizing).
+ // get filtered out eventually (but may lead to superfluous resizing).
if (i == m_tailIndex)
m_tailIndex -= 1;
else if (i == m_headIndex)
}
}
- // Holds a WorkStealingQueue, and remmoves it from the list when this object is no longer referened.
+ // Holds a WorkStealingQueue, and removes it from the list when this object is no longer referenced.
internal sealed class ThreadPoolWorkQueueThreadLocals
{
[ThreadStatic]
public delegate void WaitCallback(Object state);
- public delegate void WaitOrTimerCallback(Object state, bool timedOut); // signalled or timed out
+ public delegate void WaitOrTimerCallback(Object state, bool timedOut); // signaled or timed out
//
// This type is necessary because VS 2010's debugger looks for a method named _ThreadPoolWaitCallbacck.PerformWaitCallback