Exemplo n.º 1
0
 public ReaderWriterCount(bool fIsReentrant)
 {
     if (fIsReentrant)
     {
         this.rc = new RecursiveCounts();
     }
 }
Exemplo n.º 2
0
        public void ExitUpgradeableReadLock()
        {
            int id = Thread.CurrentThread.ManagedThreadId;

            if (!this.fIsReentrant)
            {
                if (id != this.upgradeLockOwnerId)
                {
                    throw new SynchronizationLockException("SynchronizationLockException_MisMatchedUpgrade");
                }
                this.EnterMyLock();
            }
            else
            {
                this.EnterMyLock();
                ReaderWriterCount threadRWCount = this.GetThreadRWCount(id, true);
                if (threadRWCount == null)
                {
                    this.ExitMyLock();
                    throw new SynchronizationLockException("SynchronizationLockException_MisMatchedUpgrade");
                }
                RecursiveCounts rc = threadRWCount.rc;
                if (rc.upgradecount < 1)
                {
                    this.ExitMyLock();
                    throw new SynchronizationLockException("SynchronizationLockException_MisMatchedUpgrade");
                }
                rc.upgradecount--;
                if (rc.upgradecount > 0)
                {
                    this.ExitMyLock();
                    return;
                }
                this.fUpgradeThreadHoldingRead = false;
            }
            this.owners--;
            this.upgradeLockOwnerId = -1;
            this.ExitAndWakeUpAppropriateWaiters();
        }
Exemplo n.º 3
0
        public void ExitWriteLock()
        {
            int id = Thread.CurrentThread.ManagedThreadId;

            if (!this.fIsReentrant)
            {
                if (id != this.writeLockOwnerId)
                {
                    throw new SynchronizationLockException("SynchronizationLockException_MisMatchedWrite");
                }
                this.EnterMyLock();
            }
            else
            {
                this.EnterMyLock();
                ReaderWriterCount threadRWCount = this.GetThreadRWCount(id, false);
                if (threadRWCount == null)
                {
                    this.ExitMyLock();
                    throw new SynchronizationLockException("SynchronizationLockException_MisMatchedWrite");
                }
                RecursiveCounts rc = threadRWCount.rc;
                if (rc.writercount < 1)
                {
                    this.ExitMyLock();
                    throw new SynchronizationLockException("SynchronizationLockException_MisMatchedWrite");
                }
                rc.writercount--;
                if (rc.writercount > 0)
                {
                    this.ExitMyLock();
                    return;
                }
            }
            this.ClearWriterAcquired();
            this.writeLockOwnerId = -1;
            this.ExitAndWakeUpAppropriateWaiters();
        }