Пример #1
0
 public long WaitFor(long position, Sequence sequence)
 {
     long current;
     while ((current = sequence.VolatileGet()) < position)
     {
         lock (_sync)
         {
             _waitingQueueSize++;
             current = sequence.VolatileGet();
             if (position <= current)
             {
                 _waitingQueueSize--;
                 return current;
             }
             Monitor.Wait(_sync);
             _waitingQueueSize--;
         }
     }
     return current;
 }
Пример #2
0
        public long WaitFor(long position, Sequence sequence)
        {
            long current;

            while ((current = sequence.VolatileGet()) < position)
            {
                lock (_sync)
                {
                    _waitingQueueSize++;
                    current = sequence.VolatileGet();
                    if (position <= current)
                    {
                        _waitingQueueSize--;
                        return(current);
                    }
                    Monitor.Wait(_sync);
                    _waitingQueueSize--;
                }
            }
            return(current);
        }
        public long Claim(int count)
        {
            long claimed  = _nextFree.InterlockedIncrement(count);
            long lastFree = _lastFree.VolatileGet();

            if (claimed > lastFree)
            {
                long newLastFree = WaitForAvailable(claimed - _bufferSize);
                _nextFree.CompareAndSwap(newLastFree, lastFree);
            }

            return(claimed);
        }