public bool IsOpened( ref int maxQueuedCount )
{
if( Interlocked.Decrement( ref _sample ) == 0 )
{
if( Interlocked.CompareExchange( ref _sampleReentrantFlag, 1, 0 ) == 1 ) Interlocked.Increment( ref _ignoredConcurrentCallCount );
else
{
int waitingCount = _count();
if( maxQueuedCount < waitingCount ) maxQueuedCount = waitingCount;
Thread.MemoryBarrier();
if( _opened )
{
if( waitingCount > _maxCapacity )
{
_opened = false;
Thread.MemoryBarrier();
}
}
else
{
if( waitingCount > _reenableCapacity )
{
_opened = true;
Thread.MemoryBarrier();
}
}
Interlocked.Exchange( ref _sampleReentrantFlag, 0 );
Interlocked.Exchange( ref _sample, _samplingCount );
}
return _opened;
}
Thread.MemoryBarrier();
return _opened;
}