public IDisposable Schedule(Action task)
            {
                if (Volatile.Read(ref cancelled) != 0)
                {
                    return(EmptyDisposable.Instance);
                }
                var t = new InterruptibleAction(task);

                queue.Offer(t);
                Drain();
                return(t);
            }
Пример #2
0
            internal void InnerNext(FlatMapInnerSubscriber inner, R item)
            {
                if (Volatile.Read(ref wip) == 0 && Interlocked.CompareExchange(ref wip, 1, 0) == 0)
                {
                    long e = emitted;
                    if (Volatile.Read(ref requested) != e)
                    {
                        actual.OnNext(item);
                        emitted = e + 1;
                        inner.Request(1);
                    }
                    else
                    {
                        ISimpleQueue <R> q = inner.GetOrCreateQueue();
                        q.Offer(item);
                    }
                    if (Interlocked.Decrement(ref wip) == 0)
                    {
                        return;
                    }
                }
                else
                {
                    ISimpleQueue <R> q = inner.GetOrCreateQueue();
                    q.Offer(item);
                    if (Interlocked.Increment(ref wip) != 1)
                    {
                        return;
                    }
                }

                DrainLoop();
            }
 public override void OnNext(T item)
 {
     if (!done && !IsCancelled)
     {
         queue.Offer(item);
         Drain();
     }
 }
 public void OnNext(T element)
 {
     if (fusionMode == FusionSupport.NONE)
     {
         queue.Offer(element);
     }
     parent.Drain();
 }
Пример #5
0
 public void OnNext(T element)
 {
     if (sourceMode == FusionSupport.NONE)
     {
         queue.Offer(element);
     }
     Schedule();
 }
 public void OnNext(V element)
 {
     if (Volatile.Read(ref cancelled))
     {
         return;
     }
     queue.Offer(element);
     Drain();
 }
Пример #7
0
 internal WindowBoundarySubscriber(IFlowableSubscriber <IFlowable <T> > actual, int bufferSize)
 {
     this.actual     = actual;
     this.active     = 1;
     this.queue      = new SpscLinkedArrayQueue <IFlowable <T> >(16);
     this.terminate  = OnTerminate;
     this.bufferSize = bufferSize;
     this.buffer     = new UnicastProcessor <T>(bufferSize, terminate);
     this.boundary   = new BoundarySubscriber(this);
     queue.Offer(buffer);
 }
            public void OnNext(T element)
            {
                var q   = queue;
                int idx = index;

                bool drain = false;

                if (idx == 0)
                {
                    int a = Volatile.Read(ref active);
                    if (a != 0 && Interlocked.CompareExchange(ref active, a + 1, a) == a)
                    {
                        var up = new UnicastProcessor <T>(size, OnTerminate);
                        q.Offer(up);

                        windows.Offer(up);
                        drain = true;
                    }
                }

                q.ForEach(element, CallNext);

                int c = count + 1;

                if (c == size)
                {
                    count = c - skip;

                    q.Poll(out var item);

                    item.OnComplete();
                }
                else
                {
                    count = c;
                }

                if (++idx == skip)
                {
                    index = 0;
                }
                else
                {
                    index = idx;
                }

                if (drain)
                {
                    Drain();
                }
            }
Пример #9
0
 internal bool Offer(Action task)
 {
     if (Volatile.Read(ref shutdown) == 0)
     {
         queue.Offer(task);
         if (Interlocked.Increment(ref wip) == 1)
         {
             Monitor.Enter(this);
             try
             {
                 Monitor.Pulse(this);
             }
             finally
             {
                 Monitor.Exit(this);
             }
         }
         return(true);
     }
     return(false);
 }
Пример #10
0
            public void OnNext(T element)
            {
                if (done)
                {
                    return;
                }
                R acc;

                try
                {
                    acc = scanner(accumulator, element);
                }
                catch (Exception ex)
                {
                    upstream.Cancel();
                    OnError(ex);
                    return;
                }
                accumulator = acc;
                queue.Offer(acc);
                Drain();
            }
Пример #11
0
 public void OnNext(T value)
 {
     queue.Offer(value);
     Drain();
 }
 public void OnNext(T item)
 {
     queue.Offer(item);
     Drain();
 }
Пример #13
0
 public void OnNext(T element)
 {
     queue.Offer(element);
     Schedule();
 }