コード例 #1
0
ファイル: SoaReadWriteLock.cs プロジェクト: SalarTam/CodeRich
 private void WriteToResource(SoaLockReleaser releaser)
 {
     while (!SoaReadWriteLock.IfThen(ref this.m_LockState, 0, 1))
     {
         if (SoaReadWriteLock.IfThen(ref this.m_LockState, 1, 4))
         {
             this.m_qWriters.Enqueue(releaser);
             Interlocked.Exchange(ref this.m_LockState, 1);
             return;
         }
         if (SoaReadWriteLock.IfThen(ref this.m_LockState, 2, 4) || SoaReadWriteLock.IfThen(ref this.m_LockState, 3, 4))
         {
             this.m_qWriters.Enqueue(releaser);
             Interlocked.Exchange(ref this.m_LockState, 3);
             return;
         }
         SoaReadWriteLock.StallThread();
     }
     releaser.Invoke();
 }
コード例 #2
0
ファイル: SoaReadWriteLock.cs プロジェクト: SalarTam/CodeRich
 private void ReadFromResource(SoaLockReleaser releaser)
 {
     while (!SoaReadWriteLock.IfThen(ref this.m_LockState, 0, 2) && this.m_LockState != 2)
     {
         if (SoaReadWriteLock.IfThen(ref this.m_LockState, 3, 4))
         {
             this.m_qReaders.Enqueue(releaser);
             Interlocked.Exchange(ref this.m_LockState, 3);
             return;
         }
         if (SoaReadWriteLock.IfThen(ref this.m_LockState, 1, 4))
         {
             this.m_qReaders.Enqueue(releaser);
             Interlocked.Exchange(ref this.m_LockState, 1);
             return;
         }
         SoaReadWriteLock.StallThread();
     }
     Interlocked.Increment(ref this.m_NumReadersReading);
     releaser.Invoke();
 }