Beispiel #1
0
        /// <summary>
        /// Creates a FairResourceLock, specifying a spin count.
        /// </summary>
        /// <param name="spinCount">
        /// The number of times to spin before going to sleep.
        /// </param>
        public FairResourceLock(int spinCount)
        {
            _value     = 0;
            _lock      = new SpinLock();
            _spinCount = Environment.ProcessorCount != 1 ? spinCount : 0;

            _waitersListHead        = (WaitBlock *)Marshal.AllocHGlobal(WaitBlock.SizeOf);
            _waitersListHead->Flink = _waitersListHead;
            _waitersListHead->Blink = _waitersListHead;
            _waitersListHead->Flags = 0;
            _firstSharedWaiter      = _waitersListHead;

#if !DEFER_EVENT_CREATION
            _wakeEvent = this.CreateWakeEvent();
#endif
        }
Beispiel #2
0
 internal SpinLockContext(SpinLock spinLock)
 {
     _spinLock = spinLock;
     _spinLock.Acquire();
     _disposed = false;
 }