Пример #1
0
        /// <summary>
        /// This method borrows a lock from the lowest layer (lock store).
        /// </summary>
        /// <param name="key">Generic key against which the lock is maintained</param>
        /// <returns></returns>
        private SlimLockWrapper BorrowLockObject(TKey key, bool createNew)
        {
            SlimLockWrapper retInstance = null;

            lock (_keyLockTable){
                if (_keyLockTable.ContainsKey(key))
                {
                    retInstance = _keyLockTable[key];
                }
                if (retInstance == null && !createNew)
                {
                    return(null);
                }
                if (retInstance == null)
                {
                    retInstance = _keyLockTable[key] = new SlimLockWrapper(_policy);
                }
                else if (retInstance.MarkedDeleted)
                {
                    retInstance = _keyLockTable[key] = new SlimLockWrapper(_policy);
                }
                retInstance.IncrementRef();
                return(retInstance);
            }
        }
Пример #2
0
        private void GetLock(TKey key) //, LockMode lockMode)
        {
            SlimLockWrapper slimlock = BorrowLockObject(key, true);

            slimlock.GetLock();

        }
Пример #3
0
        private SlimLockWrapper GetLockObject(TKey key)
        {
            SlimLockWrapper retInstance = null;

            lock (_keyLockTable)
            {
                if (_keyLockTable.ContainsKey(key))
                {
                    retInstance = _keyLockTable[key];
                }
                return(retInstance);
            }
        }
Пример #4
0
        private void ReleaseLock(TKey key)//, LockMode lockMode)
        {
            SlimLockWrapper lockObject = GetLockObject(key);

            if(lockObject == null)
                return;

            lockObject.ReleaseLock();

          

            ReturnLockObject(key, lockObject);
        }
Пример #5
0
        private void GetLock(TKey key, LockMode lockMode)
        {
            SlimLockWrapper slimlock = BorrowLockObject(key, true);

            switch (lockMode)
            {
            case LockMode.Reader:
                slimlock.GetReaderLock();
                return;

            case LockMode.Write:
                slimlock.GetWriterLock();
                return;
            }
        }
Пример #6
0
 /// <summary>
 /// This method returns a lock object to the lowest layer (lock store).
 /// </summary>
 /// <param name="key">Generic key against which the lock is maintained.</param>
 /// <param name="lockObject">The lock value stored.</param>
 private void ReturnLockObject(TKey key, SlimLockWrapper lockObject)
 {
     lock (_keyLockTable){
         lockObject.DecrementRef();
         if (lockObject.MarkedDeleted)
         {
             SlimLockWrapper outValue;
             if (_keyLockTable.TryGetValue(key, out outValue) &&
                 lockObject == outValue)
             {
                 _keyLockTable.Remove(key);
             }
         }
     }
 }
Пример #7
0
        private void ReleaseLock(TKey key, LockMode lockMode)
        {
            SlimLockWrapper lockObject = GetLockObject(key);

            if (lockObject == null)
            {
                return;
            }

            switch (lockMode)
            {
            case LockMode.Reader:
                lockObject.ReleaseReaderLock();
                break;

            case LockMode.Write:
                lockObject.ReleaseWriterLock();
                break;
            }

            ReturnLockObject(key, lockObject);
        }
Пример #8
0
        /// <summary>
        /// This method borrows a lock from the lowest layer (lock store).
        /// </summary>
        /// <param name="key">Generic key against which the lock is maintained</param>
        /// <returns></returns>
        private SlimLockWrapper BorrowLockObject(TKey key, bool createNew)
        {
            SlimLockWrapper retInstance;
            lock (_keyLockTable)
            {
                _keyLockTable.TryGetValue(key, out retInstance);

                if (retInstance == null && !createNew)
                {
                    return null;
                }
                if (retInstance == null)
                {
                    retInstance = _keyLockTable[key] = new SlimLockWrapper();//_policy);
                }
                else if (retInstance.MarkedDeleted){
                    retInstance = _keyLockTable[key] = new SlimLockWrapper();// _policy);
                }
                retInstance.IncrementRef();
                return retInstance;
            }
        }