diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2013-12-16 17:30:03 +0400 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2013-12-16 17:30:03 +0400 |
commit | 74a538f6725ebc83efda4bb07d5747e8a6359e19 (patch) | |
tree | 7c98de97c88c78b4aca4b25b36db310f82c26865 /Rx/NET/Source/System.Reactive.PlatformServices/Reactive | |
parent | 50e7bdb4507f7e4c2aefb7772d57d9a80f4d42b0 (diff) |
I made changes from the original source tree to match the older tree
so that we don't have to make several changes to project tree generator.
(There is actually no new sources in Rx so hopefully we can just reuse
existing modifications in the tree).
Diffstat (limited to 'Rx/NET/Source/System.Reactive.PlatformServices/Reactive')
4 files changed, 63 insertions, 9 deletions
diff --git a/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs b/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs index 4c91463..7cb011b 100644 --- a/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs +++ b/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs @@ -22,16 +22,21 @@ namespace System.Reactive.Concurrency public IDisposable StartPeriodicTimer(Action action, TimeSpan period) { - // - // MSDN documentation states the following: - // - // "If period is zero (0) or negative one (-1) milliseconds and dueTime is positive, callback is invoked once; - // the periodic behavior of the timer is disabled, but can be re-enabled using the Change method." - // - if (period <= TimeSpan.Zero) + if (period < TimeSpan.Zero) throw new ArgumentOutOfRangeException("period"); - return new PeriodicTimer(action, period); + // + // The contract for periodic scheduling in Rx is that specifying TimeSpan.Zero as the period causes the scheduler to + // call back periodically as fast as possible, sequentially. + // + if (period == TimeSpan.Zero) + { + return new FastPeriodicTimer(action); + } + else + { + return new PeriodicTimer(action, period); + } } public IDisposable QueueUserWorkItem(Action<object> action, object state) @@ -366,6 +371,37 @@ namespace System.Reactive.Concurrency } } #endif + + class FastPeriodicTimer : IDisposable + { + private readonly Action _action; + private bool disposed; + + public FastPeriodicTimer(Action action) + { + _action = action; + + new System.Threading.Thread(Loop) + { + Name = "Rx-FastPeriodicTimer", + IsBackground = true + } + .Start(); + } + + private void Loop() + { + while (!disposed) + { + _action(); + } + } + + public void Dispose() + { + disposed = true; + } + } } } #endif
\ No newline at end of file diff --git a/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/EventLoopScheduler.cs b/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/EventLoopScheduler.cs index 8739895..98df416 100644 --- a/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/EventLoopScheduler.cs +++ b/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/EventLoopScheduler.cs @@ -296,6 +296,16 @@ namespace System.Reactive.Concurrency lock (_gate) { // + // Bug fix that ensures the number of calls to Release never greatly exceeds the number of calls to Wait. + // See work item #37: https://rx.codeplex.com/workitem/37 + // +#if !NO_CDS + while (_evt.CurrentCount > 0) _evt.Wait(); +#else + while (_evt.WaitOne(TimeSpan.Zero)) { } +#endif + + // // The event could have been set by a call to Dispose. This takes priority over anything else. We quit the // loop immediately. Subsequent calls to Schedule won't ever create a new thread. // diff --git a/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/TaskPoolScheduler.cs b/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/TaskPoolScheduler.cs index a84588b..a27e7a6 100644 --- a/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/TaskPoolScheduler.cs +++ b/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Concurrency/TaskPoolScheduler.cs @@ -111,7 +111,11 @@ namespace System.Reactive.Concurrency var ct = new CancellationDisposable(); d.Disposable = ct; +#if USE_TASKEX + TaskEx.Delay(dueTime, ct.Token).ContinueWith(_ => +#else Task.Delay(dueTime, ct.Token).ContinueWith(_ => +#endif { if (!d.IsDisposed) d.Disposable = action(this, state); @@ -190,7 +194,11 @@ namespace System.Reactive.Concurrency var moveNext = default(Action); moveNext = () => { +#if USE_TASKEX + TaskEx.Delay(period, cancel.Token).ContinueWith( +#else Task.Delay(period, cancel.Token).ContinueWith( +#endif _ => { moveNext(); diff --git a/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Internal/PlatformEnlightenmentProvider.cs b/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Internal/PlatformEnlightenmentProvider.cs index 7bb597c..881178b 100644 --- a/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Internal/PlatformEnlightenmentProvider.cs +++ b/Rx/NET/Source/System.Reactive.PlatformServices/Reactive/Internal/PlatformEnlightenmentProvider.cs @@ -88,7 +88,7 @@ namespace System.Reactive.PlatformServices #if NETCF35 var name = "System.Reactive.Linq.QueryDebugger, System.Reactive.Debugger"; #else -#if CRIPPLED_REFLECTION +#if (CRIPPLED_REFLECTION && HAS_WINRT) var ifType = t.GetTypeInfo(); #else var ifType = t; |