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]); } } } }
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)); }
public LockStatus StatusOf(LockState lockState) { lock (lockAccess) { if (staleLocks.Contains(lockState)) { return(LockStatus.Locked); //not sure } return(LockStatus.Unlocked); } }
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 { } }
private void NotifyStateChanged(LockState LockState) { Action <LockState> act = locks [LockState]; switch (LockState.Status) { case LockStatus.Locked: break; case LockStatus.Unlocked: break; } act(LockState); }
void RemoveLockManager(LockState state) { lock (managers) { managers.Remove (state); } }
void AddLockStateTracker(LockState state) { lock (managers) { managers.Add (state); } }
void RemoveLockManager(LockState state) { lock (managers) { managers.Remove(state); } }
void AddLockStateTracker(LockState state) { lock (managers) { managers.Add(state); } }
private void ReportStale(LockState lockState) { lock (lockAccess) staleLocks.Add (lockState); }
private void NotifyStateChanged(LockState LockState) { Action<LockState> act = locks [LockState]; switch (LockState.Status) { case LockStatus.Locked: break; case LockStatus.Unlocked: break; } act (LockState); }
public LockStatus StatusOf(LockState lockState) { lock (lockAccess) { if (staleLocks.Contains (lockState)) { return LockStatus.Locked;//not sure } return LockStatus.Unlocked; } }
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 { } }
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]); } } } }
private void ReportStale(LockState lockState) { lock (lockAccess) staleLocks.Add(lockState); }
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); }