Exemplo n.º 1
0
            bool HandleException(ISubscriber <IList <T> > a, IQueue <BufferWork> q)
            {
                Exception ex = Volatile.Read(ref error);

                if (ex != null)
                {
                    ex = ExceptionHelper.Terminate(ref error);

                    var c = Interlocked.Exchange(ref this.s, SubscriptionHelper.Cancelled);

                    if (c == null)
                    {
                        buffers.Clear();
                        q.Clear();

                        a.OnSubscribe(EmptySubscription <IList <T> > .Instance);
                    }
                    else
                    {
                        c.Cancel();

                        buffers.Clear();
                        q.Clear();
                    }

                    a.OnError(ex);
                    return(true);
                }
                return(false);
            }
Exemplo n.º 2
0
        static void PostCompleteDrain <T>(ref long requested, ISubscriber <T> s, IQueue <T> queue, ref bool cancelled)
        {
            long r = Volatile.Read(ref requested);
            long e = COMPLETE_MASK;

            for (;;)
            {
                while (e != r)
                {
                    if (Volatile.Read(ref cancelled))
                    {
                        queue.Clear();
                        return;
                    }

                    T t;

                    if (queue.Poll(out t))
                    {
                        s.OnNext(t);
                        e++;
                    }
                    else
                    {
                        s.OnComplete();
                        return;
                    }
                }

                if (e == r)
                {
                    if (Volatile.Read(ref cancelled))
                    {
                        queue.Clear();
                        return;
                    }

                    if (queue.IsEmpty())
                    {
                        s.OnComplete();
                        return;
                    }
                }

                r = Volatile.Read(ref requested);
                if (r == e)
                {
                    r = Interlocked.Add(ref requested, -(e & REQUESTED_MASK));
                    if (r == COMPLETE_MASK)
                    {
                        break;
                    }
                    e = COMPLETE_MASK;
                }
            }
        }
Exemplo n.º 3
0
            public void Cancel()
            {
                Volatile.Write(ref cancelled, true);
                SubscriptionHelper.Cancel(ref s);

                if (QueueDrainHelper.Enter(ref wip))
                {
                    actual = null;
                    queue.Clear();
                }
            }
Exemplo n.º 4
0
            void DoCancel()
            {
                if (Interlocked.Decrement(ref groupCount) == 0)
                {
                    s.Cancel();

                    if (QueueDrainHelper.Enter(ref wip))
                    {
                        queue.Clear();
                    }
                }
            }
Exemplo n.º 5
0
        public void Clear_FlushingAllPackets_ShouldBeEmpty()
        {
            for (var i = 0; i < _testPackets.Capacity; i++)
            {
                var packet = _testPackets[i];
                _queue.Enqueue(packet);
            }

            _queue.Clear();
            var empty = _queue.IsEmpty();

            Assert.AreEqual(true, empty);
        }
            public void Cancel()
            {
                if (Volatile.Read(ref cancelled))
                {
                    return;
                }
                Volatile.Write(ref cancelled, true);
                DisposableHelper.Dispose(ref d);

                if (QueueDrainHelper.Enter(ref wip))
                {
                    queue.Clear();
                }
            }
Exemplo n.º 7
0
        static void TestQueue(IQueue <int> queue)
        {
            Console.WriteLine("should be true:{0}", queue.IsEmpty());
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);

            Console.WriteLine("should be false:{0}", queue.IsEmpty());
            Console.WriteLine("should be 1:{0}", queue.Peek());
            Console.WriteLine("should be 1:{0}", queue.Dequeue());
            Console.WriteLine("should be 2:{0}", queue.Peek());

            queue.Clear();
            Console.WriteLine("should be true:{0}", queue.IsEmpty());
            queue.Dequeue();

            QueueLL <int> queuell = new QueueLL <int>();

            Console.WriteLine("should be true:{0}", queuell.IsEmpty());
            queuell.Enqueue(1);
            queuell.Enqueue(2);
            queuell.Enqueue(3);

            Console.WriteLine("should be false:{0}", queuell.IsEmpty());
            Console.WriteLine("should be 1:{0}", queuell.Peek());
            Console.WriteLine("should be 1:{0}", queuell.Dequeue());
            Console.WriteLine("should be 2:{0}", queuell.Peek());

            queuell.Clear();
            Console.WriteLine("should be true:{0}", queuell.IsEmpty());
            queuell.Dequeue();
        }
Exemplo n.º 8
0
 // Implement the IQueue<T> interface.
 public void Clear()
 {
     lock (SyncRoot)
     {
         queue.Clear();
     }
 }
Exemplo n.º 9
0
            void Cleanup()
            {
                var a = latest;
                int n = a.Length;

                Array.Clear(a, 0, n);
                queue.Clear();
            }
Exemplo n.º 10
0
            public void Cancel()
            {
                Volatile.Write(ref cancelled, true);
                s.Cancel();

                if (QueueDrainHelper.Enter(ref wip))
                {
                    queue.Clear();
                }
            }
 public virtual void TestClear()
 {
     Assert.IsTrue(q.Offer("item1"));
     Assert.IsTrue(q.Offer("item2"));
     Assert.IsTrue(q.Offer("item3"));
     Assert.IsTrue(q.Offer("item4"));
     Assert.IsTrue(q.Offer("item5"));
     q.Clear();
     Assert.AreEqual(0, q.Count);
     Assert.IsNull(q.Poll());
 }
 public override void Cancel()
 {
     Volatile.Write(ref cancelled, true);
     s.Cancel();
     if (QueueDrainHelper.Enter(ref wip))
     {
         queue.Clear();
         enumerator?.Dispose();
         enumerator = null;
     }
 }
        /**
         * Removes all {@link Crouton}s from the queue.
         */

        public void ClearCroutonQueue()
        {
            RemoveAllMessages();

            // remove any views that may already have been added to the activity's
            // content view
            foreach (Crouton crouton in croutonQueue.ToEnumerable())
            {
                RemoveCroutonFromViewParent(crouton);
            }
            croutonQueue.Clear();
        }
Exemplo n.º 14
0
 private void очиститьToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (IsInt)
     {
         Q.Clear();
     }
     else if (Qs != null)
     {
         Qs.Clear();
     }
     refresh();
 }
Exemplo n.º 15
0
            public void Cancel()
            {
                if (Volatile.Read(ref cancelled))
                {
                    return;
                }

                Volatile.Write(ref cancelled, true);
                s.Cancel();
                open.Cancel();

                if (QueueDrainHelper.Enter(ref wip))
                {
                    foreach (var close in buffers)
                    {
                        close.Cancel();
                    }
                    buffers.Clear();
                    queue.Clear();
                }
            }
Exemplo n.º 16
0
        public void Generic(Type type)
        {
            IQueue <int> S = (IQueue <int>)Activator.CreateInstance(type);

            S.Clear();
            Assert.AreEqual(0, S.Count);
            S.Enqueue(1);
            Assert.AreEqual(1, S.Count);
            Assert.AreEqual(1, S.Front);
            Assert.AreEqual(1, S.Dequeue());
            Assert.AreEqual(0, S.Count);
        }
Exemplo n.º 17
0
            public void Cancel()
            {
                s.Cancel();
                d.Dispose();
                worker.Dispose();

                if (QueueDrainHelper.Enter(ref wip))
                {
                    queue.Clear();
                    buffer = null;
                }
            }
        public void EnqueueFiveItems_ShouldHaveFiveItems()
        {
            //Arrange
            _queue.Clear();
            _queue.Enqueue(1);
            _queue.Enqueue(2);
            _queue.Enqueue(3);
            _queue.Enqueue(4);
            _queue.Enqueue(5);

            //Assert
            Assert.Equal(5, _queue.Count);
            Assert.False(_queue.IsEmpty);

            var res        = -1;
            var isDequeued = _queue.TryDequeue(out res);

            Assert.True(isDequeued);
            Assert.Equal(1, res);

            isDequeued = _queue.TryDequeue(out res);
            Assert.True(isDequeued);
            Assert.Equal(2, res);

            isDequeued = _queue.TryDequeue(out res);
            Assert.True(isDequeued);
            Assert.Equal(3, res);

            isDequeued = _queue.TryDequeue(out res);
            Assert.True(isDequeued);
            Assert.Equal(4, res);

            isDequeued = _queue.TryDequeue(out res);
            Assert.True(isDequeued);
            Assert.Equal(5, res);

            isDequeued = _queue.TryDequeue(out res);
            Assert.False(isDequeued);
        }
Exemplo n.º 19
0
        public void ClearTest()
        {
            // arrange
            IQueue <int> actual   = GetFullQueueInstance();
            IQueue <int> expected = GetEmptyQueueInstance();

            // act
            actual.Clear();

            // assert
            Assert.AreEqual(0, actual.Count);
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Run the <see cref="Simulation"/> using the provided generator
        /// <see cref="DesTask"/> instances.
        /// </summary>
        /// <remarks>
        /// The array of generators must contain zero (0) or more
        /// <see cref="DesTask"/> instances; it cannot be <see langword="null"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="generators"/> is <see langword="null"/>.
        /// </exception>
        /// <param name="generators">
        /// An array of generator <see cref="DesTask"/> instances.
        /// </param>
        /// <returns>
        /// The number of <see cref="ActivationEvent"/> instances that
        /// remained in the event queue at the time the
        /// <see cref="Simulation"/> stopped.
        /// </returns>
        public virtual int Run(DesTask [] generators)
        {
            // Reset from a previous run.
            _currentTime = 0L;
            _stopTime    = ulong.MaxValue;

            ActivateGenerators(generators);

            State = SimulationState.Running;

            while (_stopTime >= _currentTime && _eventQueue.Count > 0 &&
                   _nDiscardableTasks < _eventQueue.Count)
            {
                ActivationEvent evt = _eventQueue.Dequeue();
                _currentTime = evt.Time;

                if (evt.Priority == TaskPriority.Discardable)
                {
                    _nDiscardableTasks--;
                }

                if (_currentTime > _stopTime)
                {
                    // Time to stop.  Put the event back on the event queue so
                    // it's propertly counted as one of the events not fired.
                    _eventQueue.Enqueue(evt);
                }
                else if (evt.IsPending)
                {
                    evt.Fire(this);
                }
            }

            // Make some final time updates.
            if (_currentTime < _stopTime)
            {
                _stopTime = _currentTime;
            }
            else
            {
                _currentTime = _stopTime;
            }

            int nNotRun = _eventQueue.Count;

            _eventQueue.Clear();

            State = SimulationState.Completed;

            return(nNotRun);
        }
Exemplo n.º 21
0
        public void Stop()
        {
            _isExecuting = false;
            lock (_lock)
            {
                foreach (var thread in _threadPool)
                {
                    thread.Abort();
                }
                _threadPool.Clear();

                _queue.Clear();
            }
        }
            public void Cancel()
            {
                if (Volatile.Read(ref cancelled))
                {
                    return;
                }
                Volatile.Write(ref cancelled, true);
                s.Cancel();
                arbiter.Cancel();

                if (QueueDrainHelper.Enter(ref wip))
                {
                    queue.Clear();
                }
            }
Exemplo n.º 23
0
        /// <summary>
        /// Invoked by the <see cref="Signal"/> method to resume all
        /// waiting <see cref="Task"/>s.
        /// </summary>
        private void ResumeAll()
        {
            System.Diagnostics.Debug.Assert(BlockCount > 1);
            int nWaiting = BlockCount;

            Task[] blockedTasks = new Task[nWaiting];
            _waitQ.CopyTo(blockedTasks, 0);
            _waitQ.Clear();
            for (int i = 0; i < nWaiting; i++)
            {
                Task task = blockedTasks[i];
                if (!task.Canceled)
                {
                    task.Activate(this);
                }
            }
        }
Exemplo n.º 24
0
        public virtual void Dispose()
        {
            ConnectedToXpa = false;

            collisionActor = null;

            self = null;

            collisionEvents.Clear();

            if (physicsObject != null)
            {
                physicsObject.Dispose();
            }

            game.Physics.UnregisterTransformable(this);
        }
Exemplo n.º 25
0
        private void IntQueueTestCopyTo(IQueue <int> q)
        {
            int[] arr         = { 1, 2, 3, 4, 5 };
            int[] arr_to_copy = new int[5];
            arr_to_copy[0] = 1;
            arr_to_copy[4] = 5;
            q.Clear();
            q.Enqueue(2);
            q.Enqueue(3);
            q.Enqueue(4);
            q.CopyTo(arr_to_copy, 1);
            Assert.AreEqual(arr, arr_to_copy);
            q.Enqueue(6);
            var ex = Assert.Throws <ArgumentException>(() => q.CopyTo(arr_to_copy, 1));

            Assert.That(ex.Message, Is.EqualTo("The number of elements in the source Queue<T> is greater than the available space from arrayIndex to the end of the destination array."));
        }
Exemplo n.º 26
0
        private void EnterMixingLoop()
        {
            // Retrieve the sound system/device frequency (44.1khz only for now) and the amount of samples per buffer.
            int snd_freq       = Engine.ScriptingInterface.GetCvarValue <int>("snd_freq");
            int snd_bufferSize = Engine.ScriptingInterface.GetCvarValue <int>("snd_bufferSize");

            // Time step is the amount of time (in seconds) required to process one buffer (of snd_bufferSize samples).
            float timeStep    = (float)snd_bufferSize / (float)snd_bufferSize;
            float accumelator = 0.0f;

            timer.Split();

            // Keep processing until either an engine or a sound system shutdown is requested.
            while (!Engine.ShutdownRequested && !snd_shutdownRequested)
            {
                timer.Split();

                accumelator += timer.ElapsedTime;

                while (accumelator >= timeStep)
                {
                    // Copy frontBuffer to the backBuffer.
                    lock (syncRoot)
                    {
                        while (frontBuffer.Count != 0)
                        {
                            backBuffer.Enqueue(frontBuffer.Dequeue());
                        }

                        // Reset the enqueue/dequeue positions.
                        frontBuffer.Clear();
                    }

                    // Process an entire buffer (snd_bufferSize samples).
                    mixingSystem.Process(backBuffer, snd_bufferSize);

                    // Reset the enqueue/dequeue positions.
                    backBuffer.Clear();

                    accumelator -= timeStep;
                }
            }

            // Reset the snd_shutdownRequested value.
            snd_shutdownRequested.Value = false;
        }
Exemplo n.º 27
0
        private void ReleaseResources()
        {
            if (timerReadQueue != null)
            {
                timerReadQueue.Stop();
                timerReadQueue.Elapsed -= timerReadQueue_Elapsed;
                timerReadQueue.Dispose();
            }
            if (timerProcessRequestQueue != null)
            {
                timerProcessRequestQueue.Stop();
                timerProcessRequestQueue.Elapsed -= TimerProcessingRequest_Elapsed;
                timerProcessRequestQueue.Dispose();
            }

            lock (portColletion)
            {
                BasicInformation port = null;
                while (portColletion.Count > 0)
                {
                    Thread.Sleep(200);
                    port = portColletion.Get();
                    if (port != null)
                    {
                        port.Dispose();
                    }
                }
            }

            portColletion.Clear();
            workerPoolManager.Clear();
            pluginMap.Close();

            base.PacketReceived -= OnPacketReceived;
            base.Connected      -= OnClientConnected;
            base.Disconnected   -= OnClientDisconnect;
            base.Closed         -= OnClosed;
            base.Open           -= OnOpen;
        }
Exemplo n.º 28
0
        private void StringQueueTest(IQueue <string> q)
        {
            q.Enqueue("to");
            q.Enqueue("be");
            q.Enqueue("or");
            q.Enqueue("not");
            Assert.AreEqual("to", q.Peek());
            Assert.AreEqual("to", q.Dequeue());
            Assert.AreEqual(3, q.Count);
            var sb = new StringBuilder();

            foreach (string item in q)
            {
                sb.Append(item).Append(" ");
            }
            Assert.AreEqual("be or not ", sb.ToString());
            Queue <string> q0 = new Queue <string>(q);

            Assert.AreEqual("be", q0.Dequeue());
            q.Clear();
            Assert.IsTrue(q.IsEmpty);
        }
Exemplo n.º 29
0
 void OnClearQueueClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     queue.Clear();
     UiUtility.ClearContainer <QueueItemView>(uiItems);
 }
 public void OnError(Exception e)
 {
     queue.Clear();
     actual.OnError(e);
 }