Esempio n. 1
0
 private static void ReleaseLock(object key, LockUtility.LockObject lockObj)
 {
     lock (LockUtility._lockPool)
     {
         lockObj.Decrement();
         if (lockObj.Counter != 0)
         {
             return;
         }
         LockUtility._lockPool.Remove(key);
     }
 }
Esempio n. 2
0
 public static void Lock(object key, Action action)
 {
     LockUtility.LockObject lockObj = LockUtility.GetLock(key);
     try
     {
         lock (lockObj)
             action();
     }
     finally
     {
         LockUtility.ReleaseLock(key, lockObj);
     }
 }
Esempio n. 3
0
 private static LockUtility.LockObject GetLock(object key)
 {
     lock (LockUtility._lockPool)
     {
         LockUtility.LockObject lockObject = LockUtility._lockPool[key] as LockUtility.LockObject;
         if (lockObject == null)
         {
             lockObject = new LockUtility.LockObject();
             LockUtility._lockPool[key] = (object)lockObject;
         }
         lockObject.Increate();
         return(lockObject);
     }
 }