33 * Licensing: MIT https://github.com/electricessence/Open/blob/dotnet-core/LICENSE.md
44 */
55
6- using Open . Diagnostics ;
76using Open . Disposable ;
87using System ;
98using System . Collections . Concurrent ;
@@ -40,7 +39,7 @@ public ReaderWriterLockTracker(LockRecursionPolicy policy)
4039
4140 public bool Reserve ( object context )
4241 {
43- if ( IsDisposed )
42+ if ( WasDisposed )
4443 return false ;
4544
4645 lock ( _registry )
@@ -140,15 +139,15 @@ private ReaderWriterLockTracker GetLock(TKey key, LockType type, object context,
140139 ReaderWriterLockSlimExensions . ValidateMillisecondsTimeout ( millisecondsTimeout ) ;
141140 Contract . EndContractBlock ( ) ;
142141
143- if ( IsDisposed )
142+ if ( WasDisposed )
144143 return null ;
145144
146145 // Need to be able to enter a lock before releasing access in order to prevent removal...
147146 var r = CleanupManager . ReadValue (
148147 ( ) =>
149148 {
150149 // It is possible that a read could be acquired while disposing just before the dispose.
151- if ( IsDisposed )
150+ if ( WasDisposed )
152151 return null ;
153152
154153 // Get a tracker...
@@ -161,21 +160,21 @@ private ReaderWriterLockTracker GetLock(TKey key, LockType type, object context,
161160 result = Locks . GetOrAdd ( key , k => created = LockPool . Take ( ) ) ;
162161 }
163162 // Safeguard against rare case of when a disposed tracker is retained via an exception (possibly?). :(
164- while ( ! IsDisposed && result . IsDisposed ) ;
163+ while ( ! WasDisposed && result . WasDisposed ) ;
165164
166165
167166 // If the one created is not the one retrieved, go ahead and add it to the pool so it doesn't go to waste.
168167 if ( created != null && created != result )
169168 {
170- if ( IsDisposed )
169+ if ( WasDisposed )
171170 created . Dispose ( ) ;
172171 else
173172 LockPool . Give ( created ) ;
174173 }
175174
176175 // This should never get out of sync, but just in case...
177176 var rlock = result . Lock ;
178- if ( rlock == null || result . IsDisposed )
177+ if ( rlock == null || result . WasDisposed )
179178 {
180179 Debug . Fail ( "A lock tracker was retained after it was disposed." ) ;
181180 return null ;
@@ -188,7 +187,7 @@ private ReaderWriterLockTracker GetLock(TKey key, LockType type, object context,
188187 }
189188
190189 // Quick check to avoid further processes...
191- if ( IsDisposed )
190+ if ( WasDisposed )
192191 return null ;
193192
194193 var lockHeld = false ;
@@ -200,7 +199,7 @@ private ReaderWriterLockTracker GetLock(TKey key, LockType type, object context,
200199 }
201200 catch ( LockRecursionException lrex )
202201 {
203- lrex . WriteToDebug ( ) ;
202+ Debug . WriteLine ( lrex . ToString ( ) ) ;
204203 Debugger . Break ( ) ; // Need to be able to track down source.
205204 throw ;
206205 }
@@ -215,7 +214,7 @@ private ReaderWriterLockTracker GetLock(TKey key, LockType type, object context,
215214
216215 // In the rare case that a dispose could be initiated during this ReadValue:
217216 // We need to not propagate locking...
218- if ( r == null || ! IsDisposed ) return r ;
217+ if ( r == null || ! WasDisposed ) return r ;
219218 ReleaseLock ( r . Lock , type ) ;
220219 r . Clear ( context ) ;
221220
@@ -268,7 +267,7 @@ private void ReleaseLock(ReaderWriterLockSlim target, LockType type)
268267 break ;
269268 }
270269
271- if ( IsDisposed ) return ;
270+ if ( WasDisposed ) return ;
272271 UpdateCleanupDelay ( ) ;
273272
274273 //SetCleanup(CleanupMode.ImmediateSynchronous);
@@ -307,7 +306,7 @@ private bool Execute(TKey key, LockType type, Action<ReaderWriterLockSlim> closu
307306 }
308307 catch ( Exception ex )
309308 {
310- ex . WriteToDebug ( ) ;
309+ Debug . WriteLine ( ex . ToString ( ) ) ;
311310 // The above cannot fail or dire concequences...
312311 Debugger . Break ( ) ;
313312 throw ;
@@ -670,7 +669,7 @@ private void CleanupInternal()
670669 if ( ! tempLock . CanDispose || ! Locks . TryRemove ( key , out tempLock ) || tempLock == null ) continue ;
671670
672671#if DEBUG
673- if ( tempLock . IsDisposed && ! IsDisposed )
672+ if ( tempLock . WasDisposed && ! WasDisposed )
674673 {
675674 // Possilby caused by an exception?
676675 Debug . Fail ( "A tracker was disposed while in the lock registry." ) ;
@@ -679,10 +678,10 @@ private void CleanupInternal()
679678
680679 //lock (tempLock)
681680 //{
682- if ( tempLock . IsDisposed ) continue ;
681+ if ( tempLock . WasDisposed ) continue ;
683682 if ( tempLock . CanDispose )
684683 {
685- if ( IsDisposed )
684+ if ( WasDisposed )
686685 {
687686 // Don't add back to the pool, just get rid of..
688687 tempLock . Dispose ( ) ;
@@ -709,7 +708,7 @@ private void CleanupInternal()
709708 protected void UpdateCleanupDelay ( )
710709 {
711710 // This presents a maximum delay of 10 seconds and if the number of lock counts get's over 100 it will decrease the time before cleanup.
712- if ( ! IsDisposed )
711+ if ( ! WasDisposed )
713712 CleanupDelay = Math . Max ( Math . Min ( 1000000 / ( Locks . Count + 1 ) , 10000 ) , 1000 ) ; // Don't allow for less than.
714713 }
715714
@@ -739,7 +738,7 @@ protected void UpdateCleanupDelay()
739738 // }
740739
741740 //#if DEBUG
742- // if (target.Where(t => t is DisposableBase).Cast<DisposableBase>().Any(t => t.IsDisposed ))
741+ // if (target.Where(t => t is DisposableBase).Cast<DisposableBase>().Any(t => t.WasDisposed ))
743742 // Debug.Fail("Disposed object retained in bag.");
744743 //#endif
745744
@@ -758,7 +757,7 @@ protected override void OnCleanup()
758757 {
759758
760759 // Prevents new locks from being acquired while a cleanup is active.
761- var lockHeld = CleanupManager . WriteConditional ( write => ! IsDisposed , ( ) =>
760+ var lockHeld = CleanupManager . WriteConditional ( write => ! WasDisposed , ( ) =>
762761 {
763762 UpdateCleanupDelay ( ) ;
764763
@@ -770,15 +769,15 @@ protected override void OnCleanup()
770769 //ContextPool.TrimTo(maxCount * 2);
771770 LockPool . TrimTo ( maxCount ) ;
772771
773- //if (Debugger.IsAttached && LockPool.Any(l => l.IsDisposed ))
772+ //if (Debugger.IsAttached && LockPool.Any(l => l.WasDisposed ))
774773 // Debug.Fail("LockPool is retaining a disposed tracker.");
775774
776775 if ( count == 0 )
777776 ClearCleanup ( ) ;
778777
779778 } , 10000 ) ; // Use a timeout to ensure a busy collection isn't over locked.
780779
781- if ( IsDisposed ) return ;
780+ if ( WasDisposed ) return ;
782781 if ( lockHeld ) return ;
783782 // Just to be sure...
784783 Debug . WriteLine ( "ReadWriteHelper cleanup deferred." ) ;
0 commit comments