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