Exemple #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]);
             }
         }
     }
 }
Exemple #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));
 }
Exemple #3
0
 public LockStatus StatusOf(LockState lockState)
 {
     lock (lockAccess) {
         if (staleLocks.Contains(lockState))
         {
             return(LockStatus.Locked);                   //not sure
         }
         return(LockStatus.Unlocked);
     }
 }
Exemple #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 {
     }
 }
Exemple #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);
        }
Exemple #6
0
 void RemoveLockManager(LockState state)
 {
     lock (managers) {
         managers.Remove (state);
     }
 }
Exemple #7
0
 void AddLockStateTracker(LockState state)
 {
     lock (managers) {
         managers.Add (state);
     }
 }
Exemple #8
0
 void RemoveLockManager(LockState state)
 {
     lock (managers) {
         managers.Remove(state);
     }
 }
Exemple #9
0
 void AddLockStateTracker(LockState state)
 {
     lock (managers) {
         managers.Add(state);
     }
 }
Exemple #10
0
 private void ReportStale(LockState lockState)
 {
     lock (lockAccess)
         staleLocks.Add (lockState);
 }
Exemple #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);
        }
Exemple #12
0
 public LockStatus StatusOf(LockState lockState)
 {
     lock (lockAccess) {
         if (staleLocks.Contains (lockState)) {
             return LockStatus.Locked;//not sure
         }
         return LockStatus.Unlocked;
     }
 }
Exemple #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 {
     }
 }
Exemple #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]);
             }
         }
     }
 }
Exemple #15
0
 private void ReportStale(LockState lockState)
 {
     lock (lockAccess)
         staleLocks.Add(lockState);
 }
Exemple #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);
 }