// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. using System; namespace System.Reactive.Concurrency { /// /// Efficient scheduler queue that maintains scheduled items sorted by absolute time. /// /// Absolute time representation type. /// This type is not thread safe; users should ensure proper synchronization. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix", Justification = "But it *is* a queue!")] public class SchedulerQueue where TAbsolute : IComparable { private readonly PriorityQueue> _queue; /// /// Creates a new scheduler queue with a default initial capacity. /// public SchedulerQueue() : this(1024) { } /// /// Creats a new scheduler queue with the specified initial capacity. /// /// Initial capacity of the scheduler queue. /// is less than zero. public SchedulerQueue(int capacity) { if (capacity < 0) throw new ArgumentOutOfRangeException("capacity"); _queue = new PriorityQueue>(capacity); } /// /// Gets the number of scheduled items in the scheduler queue. /// public int Count { get { return _queue.Count; } } /// /// Enqueues the specified work item to be scheduled. /// /// Work item to be scheduled. public void Enqueue(ScheduledItem scheduledItem) { _queue.Enqueue(scheduledItem); } /// /// Removes the specified work item from the scheduler queue. /// /// Work item to be removed from the scheduler queue. /// true if the item was found; false otherwise. public bool Remove(ScheduledItem scheduledItem) { return _queue.Remove(scheduledItem); } /// /// Dequeues the next work item from the scheduler queue. /// /// Next work item in the scheduler queue (removed). public ScheduledItem Dequeue() { return _queue.Dequeue(); } /// /// Peeks the next work item in the scheduler queue. /// /// Next work item in the scheduler queue (not removed). public ScheduledItem Peek() { return _queue.Peek(); } } }