public void AcquireReaderLock() { #if !MONO && !PocketPC if (UseNativeSRWLock) { NativeMethods.AcquireSRWLockShared(ref LockSRW); } else #endif { #if UseFastResourceLock pLock.AcquireShared(); #else Thread.BeginCriticalRegion(); while (Interlocked.CompareExchange(ref busy, 1, 0) != 0) { Thread.Sleep(1); } Interlocked.Increment(ref readCount); // somehow this fix deadlock on heavy reads Thread.Sleep(0); Thread.Sleep(0); Thread.Sleep(0); Thread.Sleep(0); Thread.Sleep(0); Thread.Sleep(0); Thread.Sleep(0); Interlocked.Exchange(ref busy, 0); #endif } }
public void AcquireReaderLock() { if (UseNativeSRWLock) { NativeMethods.AcquireSRWLockShared(ref LockSRW); } else { pLock.AcquireShared(); Thread.BeginCriticalRegion(); while (Interlocked.CompareExchange(ref busy, 1, 0) != 0) { Thread.Sleep(1); } Interlocked.Increment(ref readCount); // somehow this fix deadlock on heavy reads Thread.Sleep(0); Thread.Sleep(0); Thread.Sleep(0); Thread.Sleep(0); Thread.Sleep(0); Thread.Sleep(0); Thread.Sleep(0); Interlocked.Exchange(ref busy, 0); } }