Skip to content

Commit

Permalink
Special case the uwp sync context 😭 (#2046)
Browse files Browse the repository at this point in the history
* Special case the uwp sync context 😭

* Attempt #2

* Add changelog
  • Loading branch information
nirinchev authored Oct 2, 2020
1 parent 8a8c72a commit fe086ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 63 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 5.1.2 (TBD)
------------------

### Enhancements
* None

### Fixed
* Fixed an issue that would result in `Realm accessed from incorrect thread` exception being thrown when accessing a Realm instance on the main thread in UWP apps. (Issue [#2045](https://github.com/realm/realm-dotnet/issues/2045))

### Compatibility
* Realm Object Server: 3.23.1 or later.
* Realm Studio: 5.0.0 or later.

### Internal
* Using Sync 5.0.28 and Core 6.1.3.

## 5.1.1 (2020-10-02)
------------------

Expand Down
62 changes: 0 additions & 62 deletions Realm/Realm/Extensions/SynchronizationContextExtensions.cs

This file was deleted.

5 changes: 4 additions & 1 deletion Realm/Realm/Native/SynchronizationContextScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ internal static class SynchronizationContextScheduler

private class Scheduler
{
private readonly int _threadId;

private volatile bool _isReleased;
private SynchronizationContext _context;

Expand All @@ -57,6 +59,7 @@ internal Scheduler(SynchronizationContext context)
Argument.NotNull(context, nameof(context));

_context = context;
_threadId = Environment.CurrentManagedThreadId;
}

internal void Post(IntPtr function_ptr)
Expand All @@ -70,7 +73,7 @@ internal void Post(IntPtr function_ptr)
}, null);
}

internal bool IsOnContext(Scheduler other) => _context.IsSameAs(other?._context ?? SynchronizationContext.Current);
internal bool IsOnContext(Scheduler other) => _context == (other?._context ?? SynchronizationContext.Current) || _threadId == (other?._threadId ?? Environment.CurrentManagedThreadId);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void Invalidate()
Expand Down

0 comments on commit fe086ef

Please sign in to comment.