Accord.SpinLock.Enter C# (CSharp) Method

Enter() public method

Acquires the lock.
public Enter ( bool &taken ) : void
taken bool
return void
        public void Enter(ref bool taken)
        {
            if (Interlocked.CompareExchange(ref lockObj, 1, 0) != 0)
            {
                int count = 0;
                while (Interlocked.CompareExchange(ref lockObj, 1, 0) != 0)
                {
                    count++;

                    if (Environment.ProcessorCount > 1 && count <= 5)
                        Thread.SpinWait(25);
                    else
                        Thread.Sleep(0);
                }
            }

            taken = true;
        }