Exemplo n.º 1
0
        internal void Release(IDisposableWithData <LockState> token)
        {
            lock (_mutex)
            {
                _currentTokens.Remove(token);

                // if there are still locks, then releasing this specific lock has no effect anyway
                if (_currentTokens.Any())
                {
                    return;
                }

                // give priority to writers
                if (_writerQueue.Any())
                {
                    var drt = _writerQueue.Dequeue();
                    _currentTokens.Add(drt.Result as IDisposableWithData <LockState>);
                    drt.Complete();
                    return;
                }

                // if we got here, then there are only readers waiting
                while (_readerQueue.Any())
                {
                    var drt = _readerQueue.Dequeue();
                    _currentTokens.Add(drt.Result as IDisposableWithData <LockState>);
                    drt.Complete();
                }
            }
        }
 public static void OnDispose(IDisposableWithData <int> disposable)
 {
     Console.WriteLine("Disposing object with data: " + disposable.Data);
 }