// Allows one readLock to upgrade to a writeLock even if // there are other readLocks as long as all other // readLocks are also blocked in this method: internal virtual void UpgradeReadToWrite() { lock (this) { System.Diagnostics.Debug.Assert(readCount > 0); upgradeCount++; while (readCount > upgradeCount || writeThread != null) { DoWait(); } writeThread = ThreadClass.Current(); readCount--; upgradeCount--; } }
internal virtual void AcquireWrite() { lock (this) { System.Diagnostics.Debug.Assert(writeThread != ThreadClass.Current()); while (writeThread != null || readCount > 0) DoWait(); // We could have been closed while we were waiting: EnsureOpen(); writeThread = ThreadClass.Current(); } }
internal virtual void ReleaseWrite() { lock (this) { System.Diagnostics.Debug.Assert(ThreadClass.Current() == writeThread); writeThread = null; System.Threading.Monitor.PulseAll(this); } }
/// <summary> /// Gets the currently running thread /// </summary> /// <returns>The currently running thread</returns> public static ThreadClass Current() { if (This == null) { This = new ThreadClass(); This.Instance = Thread.CurrentThread; } return This; }