Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static TimeSpan Time
/// </summary>
[Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Now marked as obsolete.")]
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete(Constants_Core.OBSOLETE_SCHEDULEREQUIRED)] // Preferring static method call over instance method call.
[Obsolete(Constants_Core.ObsoleteSchedulerequired)] // Preferring static method call over instance method call.
public bool ScheduleRequired => IsScheduleRequired;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed class DisableOptimizationsScheduler : SchedulerWrapper
public DisableOptimizationsScheduler(IScheduler scheduler)
: base(scheduler)
{
_optimizationInterfaces = Scheduler.OPTIMIZATIONS;
_optimizationInterfaces = Scheduler.Optimizations;
}

public DisableOptimizationsScheduler(IScheduler scheduler, Type[] optimizationInterfaces)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public partial class LocalScheduler
/// Threshold where an item is considered to be short term work or gets moved from
/// long term to short term.
/// </summary>
private static readonly TimeSpan SHORTTERM = TimeSpan.FromSeconds(10);
private static readonly TimeSpan ShortTerm = TimeSpan.FromSeconds(10);

/// <summary>
/// Maximum error ratio for timer drift. We've seen machines with 10s drift on a
Expand All @@ -79,27 +79,27 @@ public partial class LocalScheduler
/// enough time to transition work to short term and as a courtesy to the
/// destination scheduler to manage its queues etc.
/// </summary>
private const int MAXERRORRATIO = 1000;
private const int MaxErrorRatio = 1000;

/// <summary>
/// Minimum threshold for the long term timer to fire before the queue is reevaluated
/// for short term work. This value is chosen to be less than SHORTTERM in order to
/// ensure the timer fires and has work to transition to the short term queue.
/// </summary>
private static readonly TimeSpan LONGTOSHORT = TimeSpan.FromSeconds(5);
private static readonly TimeSpan LongToShort = TimeSpan.FromSeconds(5);

/// <summary>
/// Threshold used to determine when a short term timer has fired too early compared
/// to the absolute due time. This provides a last chance protection against early
/// completion of scheduled work, which can happen in case of time adjustment in the
/// operating system (cf. GetSystemTimeAdjustment).
/// </summary>
private static readonly TimeSpan RETRYSHORT = TimeSpan.FromMilliseconds(50);
private static readonly TimeSpan RetryShort = TimeSpan.FromMilliseconds(50);

/// <summary>
/// Longest interval supported by timers in the BCL.
/// </summary>
private static readonly TimeSpan MAXSUPPORTEDTIMER = TimeSpan.FromMilliseconds((1L << 32) - 2);
private static readonly TimeSpan MaxSupportedTimer = TimeSpan.FromMilliseconds((1L << 32) - 2);

/// <summary>
/// Creates a new local scheduler.
Expand Down Expand Up @@ -153,7 +153,7 @@ private IDisposable Enqueue<TState>(TState state, DateTimeOffset dueTime, Func<I

var workItem = new WorkItem<TState>(this, state, dueTime, action);

if (due <= SHORTTERM)
if (due <= ShortTerm)
{
ScheduleShortTermWork(workItem);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ private IDisposable ExecuteNextShortTermWorkItem(IScheduler scheduler, IDisposab
// have only "little" impact (range of 100s of ms). On an absolute time scale, we
// don't provide stronger guarantees.
//
if (next.DueTime - next.Scheduler.Now >= RETRYSHORT)
if (next.DueTime - next.Scheduler.Now >= RetryShort)
{
ScheduleShortTermWork(next);
}
Expand Down Expand Up @@ -324,13 +324,13 @@ private static void UpdateLongTermProcessingTimer()
// error due to drift is negligible.
//
var due = Scheduler.Normalize(next.DueTime - next.Scheduler.Now);
var remainder = TimeSpan.FromTicks(Math.Max(due.Ticks / MAXERRORRATIO, LONGTOSHORT.Ticks));
var remainder = TimeSpan.FromTicks(Math.Max(due.Ticks / MaxErrorRatio, LongToShort.Ticks));
var dueEarly = due - remainder;

//
// Limit the interval to maximum supported by underlying Timer.
//
var dueCapped = TimeSpan.FromTicks(Math.Min(dueEarly.Ticks, MAXSUPPORTEDTIMER.Ticks));
var dueCapped = TimeSpan.FromTicks(Math.Min(dueEarly.Ticks, MaxSupportedTimer.Ticks));

_nextLongTermWorkItem = next;
_nextLongTermTimer.Disposable = ConcurrencyAbstractionLayer.Current.StartTimer(_ => EvaluateLongTermQueue(), null, dueCapped);
Expand All @@ -352,7 +352,7 @@ private static void EvaluateLongTermQueue()
next = _longTerm.Peek();

var due = Scheduler.Normalize(next.DueTime - next.Scheduler.Now);
if (due >= SHORTTERM)
if (due >= ShortTerm)
{
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public SchedulePeriodicStopwatch(IScheduler scheduler, TState state, TimeSpan pe
_stopwatchProvider = stopwatchProvider;

_state = state;
_runState = STOPPED;
_runState = Stopped;
}

private TState _state;
Expand Down Expand Up @@ -362,10 +362,10 @@ public SchedulePeriodicStopwatch(IScheduler scheduler, TState state, TimeSpan pe
// (d) Dispose returned object from Start --> scheduled work is cancelled
// (e) Dispose returned object from Start --> unblocks _resumeEvent, Tick exits
//
private const int STOPPED = 0;
private const int RUNNING = 1;
private const int SUSPENDED = 2;
private const int DISPOSED = 3;
private const int Stopped = 0;
private const int Running = 1;
private const int Suspended = 2;
private const int Disposed = 3;

private IDisposable _task;

Expand All @@ -375,7 +375,7 @@ public IDisposable Start()

_stopwatch = _stopwatchProvider.StartStopwatch();
_nextDue = _period;
_runState = RUNNING;
_runState = Running;

Disposable.TrySetSingle(ref _task, _scheduler.Schedule(this, _nextDue, (@this, a) => @this.Tick(a)));
return this;
Expand All @@ -398,7 +398,7 @@ private void Tick(Action<SchedulePeriodicStopwatch<TState>, TimeSpan> recurse)
{
lock (_gate)
{
if (_runState == RUNNING)
if (_runState == Running)
{
//
// This is the fast path. We just let the stopwatch continue to
Expand All @@ -410,7 +410,7 @@ private void Tick(Action<SchedulePeriodicStopwatch<TState>, TimeSpan> recurse)
break;
}

if (_runState == DISPOSED)
if (_runState == Disposed)
{
//
// In case the periodic job gets disposed but we are currently
Expand All @@ -427,7 +427,7 @@ private void Tick(Action<SchedulePeriodicStopwatch<TState>, TimeSpan> recurse)
// to block such that future reevaluations of the next due time
// will pick up the cumulative inactive time delta.
//
Debug.Assert(_runState == SUSPENDED);
Debug.Assert(_runState == Suspended);
}

//
Expand All @@ -449,7 +449,7 @@ private void Cancel()

lock (_gate)
{
_runState = DISPOSED;
_runState = Disposed;

if (!Environment.HasShutdownStarted)
{
Expand All @@ -476,10 +476,10 @@ private void Suspending(object sender, HostSuspendingEventArgs args)
//
lock (_gate)
{
if (_runState == RUNNING)
if (_runState == Running)
{
_suspendedAt = _stopwatch.Elapsed;
_runState = SUSPENDED;
_runState = Suspended;

if (!Environment.HasShutdownStarted)
{
Expand Down Expand Up @@ -510,10 +510,10 @@ private void Resuming(object sender, HostResumingEventArgs args)
//
lock (_gate)
{
if (_runState == SUSPENDED)
if (_runState == Suspended)
{
_inactiveTime += _stopwatch.Elapsed - _suspendedAt;
_runState = RUNNING;
_runState = Running;

if (!Environment.HasShutdownStarted)
{
Expand Down Expand Up @@ -573,8 +573,8 @@ public IDisposable Start()
// The protocol using the three commands is explained in the Tick implementation below.
//
private const int TICK = 0;
private const int DISPATCH_START = 1;
private const int DISPATCH_END = 2;
private const int DispatchStart = 1;
private const int DispatchEnd = 2;

private void Tick(int command, Action<int, TimeSpan> recurse)
{
Expand All @@ -596,12 +596,12 @@ private void Tick(int command, Action<int, TimeSpan> recurse)
//
if (Interlocked.Increment(ref _pendingTickCount) == 1)
{
goto case DISPATCH_START;
goto case DispatchStart;
}

break;

case DISPATCH_START:
case DispatchStart:
try
{
_state = _action(_state);
Expand All @@ -625,11 +625,11 @@ private void Tick(int command, Action<int, TimeSpan> recurse)
// disabled using DisableOptimizations; legacy implementations of schedulers
// from the v1.x days will not have a stopwatch).
//
recurse(DISPATCH_END, TimeSpan.Zero);
recurse(DispatchEnd, TimeSpan.Zero);

break;

case DISPATCH_END:
case DispatchEnd:
//
// If work was due while we were still running user code, the count will have
// been incremented by the periodic tick handler above. In that case, we will
Expand All @@ -642,7 +642,7 @@ private void Tick(int command, Action<int, TimeSpan> recurse)
//
if (Interlocked.Decrement(ref _pendingTickCount) > 0)
{
recurse(DISPATCH_START, TimeSpan.Zero);
recurse(DispatchStart, TimeSpan.Zero);
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace System.Reactive.Concurrency
//
public static partial class Scheduler
{
internal static Type[] OPTIMIZATIONS = {
internal static Type[] Optimizations = {
typeof(ISchedulerLongRunning),
typeof(IStopwatchProvider),
typeof(ISchedulerPeriodic)
Expand Down
6 changes: 3 additions & 3 deletions Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ public static partial class Scheduler
/// <summary>
/// Gets a scheduler that schedules work on the thread pool.
/// </summary>
[Obsolete(Constants_Core.OBSOLETE_SCHEDULER_THREADPOOL)]
[Obsolete(Constants_Core.ObsoleteSchedulerThreadpool)]
public static IScheduler ThreadPool => _threadPool.Value;

private static readonly Lazy<IScheduler> _newThread = new Lazy<IScheduler>(() => Initialize("NewThread"));

/// <summary>
/// Gets a scheduler that schedules work on a new thread using default thread creation options.
/// </summary>
[Obsolete(Constants_Core.OBSOLETE_SCHEDULER_NEWTHREAD)]
[Obsolete(Constants_Core.ObsoleteSchedulerNewthread)]
public static IScheduler NewThread => _newThread.Value;

private static readonly Lazy<IScheduler> _taskPool = new Lazy<IScheduler>(() => Initialize("TaskPool"));

/// <summary>
/// Gets a scheduler that schedules work on Task Parallel Library (TPL) task pool using the default TaskScheduler.
/// </summary>
[Obsolete(Constants_Core.OBSOLETE_SCHEDULER_TASKPOOL)]
[Obsolete(Constants_Core.ObsoleteSchedulerTaskpool)]
public static IScheduler TaskPool => _taskPool.Value;

private static IScheduler Initialize(string name)
Expand Down
8 changes: 4 additions & 4 deletions Rx.NET/Source/src/System.Reactive/Concurrency/TaskHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ namespace System.Reactive.Concurrency
{
internal static class TaskHelpers
{
private const int MAX_DELAY = int.MaxValue;
private const int MaxDelay = int.MaxValue;

public static Task Delay(TimeSpan delay, CancellationToken token)
{
var milliseconds = (long)delay.TotalMilliseconds;

if (milliseconds > MAX_DELAY)
if (milliseconds > MaxDelay)
{
var remainder = delay - TimeSpan.FromMilliseconds(MAX_DELAY);
var remainder = delay - TimeSpan.FromMilliseconds(MaxDelay);

return
Task.Delay(MAX_DELAY, token)
Task.Delay(MaxDelay, token)
.ContinueWith(_ => Delay(remainder, token), TaskContinuationOptions.ExecuteSynchronously)
.Unwrap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public sealed class CompositeDisposable : ICollection<IDisposable>, ICancelable
private bool _disposed;
private List<IDisposable> _disposables;
private int _count;
private const int SHRINK_THRESHOLD = 64;
private const int ShrinkThreshold = 64;

// Default initial capacity of the _disposables list in case
// The number of items is not known upfront
private const int DEFAULT_CAPACITY = 16;
private const int DefaultCapacity = 16;

/// <summary>
/// Initializes a new instance of the <see cref="CompositeDisposable"/> class with no disposables contained by it initially.
Expand Down Expand Up @@ -85,7 +85,7 @@ public CompositeDisposable(IEnumerable<IDisposable> disposables)
else
{
// Unknown sized disposables, use the default capacity hint
Init(disposables, DEFAULT_CAPACITY);
Init(disposables, DefaultCapacity);
}
}

Expand Down Expand Up @@ -190,7 +190,7 @@ public bool Remove(IDisposable item)

current[i] = null;

if (current.Capacity > SHRINK_THRESHOLD && _count < current.Capacity / 2)
if (current.Capacity > ShrinkThreshold && _count < current.Capacity / 2)
{
var fresh = new List<IDisposable>(current.Capacity / 2);

Expand Down Expand Up @@ -357,7 +357,7 @@ public IEnumerator<IDisposable> GetEnumerator()
{
if (_disposed || _count == 0)
{
return EMPTY_ENUMERATOR;
return EmptyEnumerator;
}
// the copy is unavoidable but the creation
// of an outer IEnumerable is avoidable
Expand All @@ -380,7 +380,7 @@ public IEnumerator<IDisposable> GetEnumerator()
/// An empty enumerator for the <see cref="GetEnumerator"/>
/// method to avoid allocation on disposed or empty composites.
/// </summary>
private static readonly CompositeEnumerator EMPTY_ENUMERATOR =
private static readonly CompositeEnumerator EmptyEnumerator =
new CompositeEnumerator(new IDisposable[0]);

/// <summary>
Expand Down
Loading