Exemplo n.º 1
0
 internal void NotifyAcquired()
 {
     lock (lockStates) {
         int         Offset     = 0;
         LockState[] LockedList = new LockState[lockStates.Count];                //I have to do this, if I don't and I run out of memory bad things are gonna happen.
         try {
             foreach (LockState LockState in lockStates)
             {
                 if (System.Threading.Monitor.TryEnter(LockState))
                 {
                     LockedList [Offset++] = LockState;
                     if (LockState.Status == LockStatus.Unlocked)
                     {
                         throw new SystemException("LockManager has messed up.");
                     }
                 }
                 else
                 {
                     throw new SystemException("LockManager has messed up.");
                 }
             }
             ExecuteRequestList();
         } catch (Exception ex) {
             if (Offset != LockedList.Length)
             {
                 throw new Exception(string.Format("Something wicked happened while acquiring locks.Got {0} out of {1} locks.", Offset, LockedList.Length), ex);
             }
         } finally {
             for (int n = 0; n != Offset; n++)
             {
                 System.Threading.Monitor.Exit(LockedList [n]);
             }
         }
     }
 }
Exemplo n.º 2
0
 internal bool CanCoexistWith(LockState LockState)
 {
     if (CanCoexistWithType(LockState.lockType))
     {
         return(true);               //fine anyway, we're both probably reading
     }
     //bit if we have anything in common, We've got to wait
     return(!LockState.lockables.Overlaps(this.lockables));
 }
Exemplo n.º 3
0
 public LockStatus StatusOf(LockState lockState)
 {
     lock (lockAccess) {
         if (staleLocks.Contains(lockState))
         {
             return(LockStatus.Locked);                   //not sure
         }
         return(LockStatus.Unlocked);
     }
 }
Exemplo n.º 4
0
 public LockState CreateLock(LockType type, LockableBase[] baseDataObjectStateTrackers, int timeoutMilliSeconds, Action <LockState> stateChanged)
 {
     //TODO: aqcuire lock here or provide option to do so later and make a call-back for it.
     try {
         LockState ls = new LockState(this, type, baseDataObjectStateTrackers, NotifyStateChanged, ReportStale, TimeSpan.FromMilliseconds(timeoutMilliSeconds));
         lock (lockAccess) {
             pendingLocks.Add(ls);
         }
         return(ls);
     } catch {
         return(null);
     } finally {
     }
 }
Exemplo n.º 5
0
        private void NotifyStateChanged(LockState LockState)
        {
            Action <LockState> act = locks [LockState];

            switch (LockState.Status)
            {
            case LockStatus.Locked:

                break;

            case LockStatus.Unlocked:
                break;
            }
            act(LockState);
        }
Exemplo n.º 6
0
 void RemoveLockManager(LockState state)
 {
     lock (managers) {
         managers.Remove (state);
     }
 }
Exemplo n.º 7
0
 void AddLockStateTracker(LockState state)
 {
     lock (managers) {
         managers.Add (state);
     }
 }
Exemplo n.º 8
0
 void RemoveLockManager(LockState state)
 {
     lock (managers) {
         managers.Remove(state);
     }
 }
Exemplo n.º 9
0
 void AddLockStateTracker(LockState state)
 {
     lock (managers) {
         managers.Add(state);
     }
 }
Exemplo n.º 10
0
 private void ReportStale(LockState lockState)
 {
     lock (lockAccess)
         staleLocks.Add (lockState);
 }
Exemplo n.º 11
0
        private void NotifyStateChanged(LockState LockState)
        {
            Action<LockState> act = locks [LockState];
            switch (LockState.Status) {
            case LockStatus.Locked:

                break;
            case LockStatus.Unlocked:
                break;
            }
            act (LockState);
        }
Exemplo n.º 12
0
 public LockStatus StatusOf(LockState lockState)
 {
     lock (lockAccess) {
         if (staleLocks.Contains (lockState)) {
             return LockStatus.Locked;//not sure
         }
         return LockStatus.Unlocked;
     }
 }
Exemplo n.º 13
0
 public LockState CreateLock(LockType type, LockableBase[] baseDataObjectStateTrackers, int timeoutMilliSeconds, Action<LockState> stateChanged)
 {
     //TODO: aqcuire lock here or provide option to do so later and make a call-back for it.
     try {
         LockState ls = new LockState (this, type, baseDataObjectStateTrackers, NotifyStateChanged, ReportStale, TimeSpan.FromMilliseconds (timeoutMilliSeconds));
         lock (lockAccess) {
             pendingLocks.Add (ls);
         }
         return ls;
     } catch {
         return null;
     } finally {
     }
 }
Exemplo n.º 14
0
 internal void NotifyAcquired()
 {
     lock (lockStates) {
         int Offset = 0;
         LockState[] LockedList = new LockState[lockStates.Count];//I have to do this, if I don't and I run out of memory bad things are gonna happen.
         try {
             foreach (LockState LockState in lockStates) {
                 if (System.Threading.Monitor.TryEnter (LockState)) {
                     LockedList [Offset++] = LockState;
                     if (LockState.Status == LockStatus.Unlocked) {
                         throw new SystemException ("LockManager has messed up.");
                     }
                 } else {
                     throw new SystemException ("LockManager has messed up.");
                 }
             }
             ExecuteRequestList ();
         } catch (Exception ex) {
             if (Offset != LockedList.Length) {
                 throw new Exception (string.Format ("Something wicked happened while acquiring locks.Got {0} out of {1} locks.", Offset, LockedList.Length), ex);
             }
         } finally {
             for (int n = 0; n != Offset; n++) {
                 System.Threading.Monitor.Exit (LockedList [n]);
             }
         }
     }
 }
Exemplo n.º 15
0
 private void ReportStale(LockState lockState)
 {
     lock (lockAccess)
         staleLocks.Add(lockState);
 }
Exemplo n.º 16
0
 internal bool CanCoexistWith(LockState LockState)
 {
     if (CanCoexistWithType (LockState.lockType))
         return true;//fine anyway, we're both probably reading
     //bit if we have anything in common, We've got to wait
     return !LockState.lockables.Overlaps (this.lockables);
 }