예제 #1
0
		// 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--;
			}
		}
예제 #2
0
		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();
			}
		}
예제 #3
0
		internal virtual void  ReleaseWrite()
		{
			lock (this)
			{
				System.Diagnostics.Debug.Assert(ThreadClass.Current() == writeThread);
				writeThread = null;
				System.Threading.Monitor.PulseAll(this);
			}
		}
예제 #4
0
 /// <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;
 }