示例#1
0
        private void DoUnlock(long targetLockBit)
        {
            long currentState;
            long newState;

            do
            {
                currentState = _state;
                if (!CanUnlock(currentState, targetLockBit))
                {
                    throw new System.InvalidOperationException("Can not unlock lock that is already locked");
                }
                newState = currentState & ~targetLockBit;
            } while (!UnsafeUtil.compareAndSwapLong(this, _stateOffset, currentState, newState));
        }
示例#2
0
        private void DoLock(long targetLockBit)
        {
            long currentState;
            long newState;

            do
            {
                currentState = _state;
                while (!CanLock(currentState, targetLockBit))
                {
                    // sleep
                    Sleep();
                    currentState = _state;
                }
                newState = currentState | targetLockBit;
            } while (!UnsafeUtil.compareAndSwapLong(this, _stateOffset, currentState, newState));
        }
示例#3
0
 private static bool CompareAndSetState(long address, long expect, long update)
 {
     return(UnsafeUtil.compareAndSwapLong(null, address, expect, update));
 }