Skip to content

Commit

Permalink
64-bit atomic ops on ARM (i.e. WP7) aren't supported and throw an Exc…
Browse files Browse the repository at this point in the history
…eption
  • Loading branch information
anaisbetts committed Jul 22, 2011
1 parent acebb92 commit 3d725e3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 4 additions & 4 deletions ReactiveUI/Logging.cs
Expand Up @@ -8,7 +8,7 @@
using System.Diagnostics.Contracts;

#if DOTNETISOLDANDSAD
using System.Concurrency;
using System.Reactive.Concurrency;
#endif

namespace ReactiveUI
Expand Down Expand Up @@ -353,19 +353,19 @@ protected override void writeFatal(string message)

internal struct SilverlightSpinlock
{
long atomic;
int atomic;

public void Enter(ref bool isAcquired)
{
long id = Thread.CurrentThread.ManagedThreadId;
int id = (int)Thread.CurrentThread.ManagedThreadId;
while (Interlocked.CompareExchange(ref atomic, id, 0) != 0) { }
isAcquired = true;
}

public void Exit()
{
long id = Thread.CurrentThread.ManagedThreadId;
long thisAtomic = Interlocked.Exchange(ref atomic, 0);
int thisAtomic = Interlocked.Exchange(ref atomic, 0);
if (thisAtomic != id) {
throw new Exception("Thread " + id + " exited a spinlock it didn't own! Owning thread was " + thisAtomic);
}
Expand Down
6 changes: 3 additions & 3 deletions ReactiveUI/ObservableAsyncMRUCache.cs
Expand Up @@ -30,7 +30,7 @@ public sealed class ObservableAsyncMRUCache<TParam, TVal> : IEnableLogger
readonly MemoizingMRUCache<TParam, IObservable<TVal>> _innerCache;
readonly SemaphoreSubject<long> _callQueue;
readonly Func<TParam, IObservable<TVal>> _fetcher;
long currentCall = 0;
int currentCall = 0;

/// <summary>
/// Constructs an ObservableAsyncMRUCache object.
Expand Down Expand Up @@ -96,7 +96,7 @@ public IObservable<TVal> AsyncGet(TParam key)
return result;
}

var myCall = Interlocked.Increment(ref currentCall);
int myCall = Interlocked.Increment(ref currentCall);

var rs = new ReplaySubject<TVal>();
_callQueue.Where(x => x == myCall).Subscribe(_ => {
Expand Down Expand Up @@ -196,7 +196,7 @@ internal class SemaphoreSubject<T> : ISubject<T>, IEnableLogger
readonly ISubject<T> _inner;
Queue<T> _nextItems = new Queue<T>();
long _count;
readonly long _maxCount;
readonly int _maxCount;

public SemaphoreSubject(int maxCount, IScheduler sched = null)
{
Expand Down
6 changes: 1 addition & 5 deletions ReactiveUI/ReactiveCollection.cs
Expand Up @@ -351,7 +351,7 @@ public void Dispose()
}

[IgnoreDataMember]
long changeNotificationsSuppressed = 0;
int changeNotificationsSuppressed = 0;

/// <summary>
/// When this method is called, an object will not fire change
Expand All @@ -369,13 +369,9 @@ public IDisposable SuppressChangeNotifications()

protected bool areChangeNotificationsEnabled {
get {
#if SILVERLIGHT
// N.B. On most architectures, machine word aligned reads are
// guaranteed to be atomic - sorry WP7, you're out of luck
return changeNotificationsSuppressed == 0;
#else
return (Interlocked.Read(ref changeNotificationsSuppressed) == 0);
#endif
}
}

Expand Down

0 comments on commit 3d725e3

Please sign in to comment.