public ReaderWriterCount(bool fIsReentrant)
 {
     if (fIsReentrant)
     {
         this.rc = new RecursiveCounts();
     }
 }
 public ReaderWriterCount(bool fIsReentrant)
 {
     if (fIsReentrant)
     {
         this.rc = new RecursiveCounts();
     }
 }
Example #3
0
 public ReaderWriterCount(bool fIsReentrant)
 {
     threadid = -1;
     if (fIsReentrant)
     {
         rc = new RecursiveCounts();
     }
 }
Example #4
0
        public void ExitWriteLock()
        {
            int id = Thread.CurrentThread.ManagedThreadId;
            ReaderWriterCount lrwc;

            if (!fIsReentrant)
            {
                if (id != writeLockOwnerId)
                {
                    //You have to be holding the write lock to make this call.
                    throw new SynchronizationLockException(SR.GetString(SR.SynchronizationLockException_MisMatchedWrite));
                }
                EnterMyLock();
            }
            else
            {
                EnterMyLock();
                lrwc = GetThreadRWCount(id, false);

                if (lrwc == null)
                {
                    ExitMyLock();
                    throw new SynchronizationLockException(SR.GetString(SR.SynchronizationLockException_MisMatchedWrite));
                }

                RecursiveCounts rc = lrwc.rc;

                if (rc.writercount < 1)
                {
                    ExitMyLock();
                    throw new SynchronizationLockException(SR.GetString(SR.SynchronizationLockException_MisMatchedWrite));
                }

                rc.writercount--;
                if (rc.writercount > 0)
                {
                    ExitMyLock();
                    Thread.EndCriticalRegion();
                    return;
                }
            }

            Debug.Assert((owners & WRITER_HELD) > 0, "Calling ReleaseWriterLock when no write lock is held");

            ClearWriterAcquired();

            writeLockOwnerId = -1;

            ExitAndWakeUpAppropriateWaiters();
            Thread.EndCriticalRegion();
        }
Example #5
0
        public void ExitUpgradeableReadLock()
        {
            int id = Thread.CurrentThread.ManagedThreadId;
            ReaderWriterCount lrwc;

            if (!fIsReentrant)
            {
                if (id != upgradeLockOwnerId)
                {
                    //You have to be holding the upgrade lock to make this call.
                    throw new SynchronizationLockException(SR.GetString(SR.SynchronizationLockException_MisMatchedUpgrade));
                }
                EnterMyLock();
            }
            else
            {
                EnterMyLock();
                lrwc = GetThreadRWCount(id, true);

                if (lrwc == null)
                {
                    ExitMyLock();
                    throw new SynchronizationLockException(SR.GetString(SR.SynchronizationLockException_MisMatchedUpgrade));
                }

                RecursiveCounts rc = lrwc.rc;

                if (rc.upgradecount < 1)
                {
                    ExitMyLock();
                    throw new SynchronizationLockException(SR.GetString(SR.SynchronizationLockException_MisMatchedUpgrade));
                }

                rc.upgradecount--;

                if (rc.upgradecount > 0)
                {
                    ExitMyLock();
                    Thread.EndCriticalRegion();
                    return;
                }

                fUpgradeThreadHoldingRead = false;
            }

            owners--;
            upgradeLockOwnerId = -1;

            ExitAndWakeUpAppropriateWaiters();
            Thread.EndCriticalRegion();
        }
        public void ExitUpgradeableReadLock()
        {
            int managedThreadId = Thread.CurrentThread.ManagedThreadId;

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

            if (!this.fIsReentrant)
            {
                if (managedThreadId != this.writeLockOwnerId)
                {
                    throw new SynchronizationLockException(System.SR.GetString("SynchronizationLockException_MisMatchedWrite"));
                }
                this.EnterMyLock();
            }
            else
            {
                this.EnterMyLock();
                ReaderWriterCount threadRWCount = this.GetThreadRWCount(managedThreadId, false);
                if (threadRWCount == null)
                {
                    this.ExitMyLock();
                    throw new SynchronizationLockException(System.SR.GetString("SynchronizationLockException_MisMatchedWrite"));
                }
                RecursiveCounts rc = threadRWCount.rc;
                if (rc.writercount < 1)
                {
                    this.ExitMyLock();
                    throw new SynchronizationLockException(System.SR.GetString("SynchronizationLockException_MisMatchedWrite"));
                }
                rc.writercount--;
                if (rc.writercount > 0)
                {
                    this.ExitMyLock();
                    Thread.EndCriticalRegion();
                    return;
                }
            }
            this.ClearWriterAcquired();
            this.writeLockOwnerId = -1;
            this.ExitAndWakeUpAppropriateWaiters();
            Thread.EndCriticalRegion();
        }
Example #8
0
 public ReaderWriterCount(bool isReentrant)
 {
   ThreadId = -1;
   if (isReentrant)
     Rc = new RecursiveCounts();
 }