Exemplo n.º 1
0
 public void Request(long n)
 {
     if (n <= 0L)
     {
         throw new ArgumentOutOfRangeException(nameof(n), "Positive request amount expected");
     }
     for (;;)
     {
         long r = Volatile.Read(ref requested);
         if (r == long.MinValue)
         {
             break;
         }
         long u = r + n;
         if (u < 0L)
         {
             u = long.MaxValue;
         }
         if (Interlocked.CompareExchange(ref requested, u, r) == r)
         {
             parent.Replay(this);
             break;
         }
     }
 }