Accord.SpinLock.Enter C# (CSharp) 메소드

Enter() 공개 메소드

Acquires the lock.
public Enter ( bool &taken ) : void
taken bool
리턴 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;
        }