• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-dotnet / 5716220196

31 Jul 2023 02:52PM UTC coverage: 82.478% (-0.3%) from 82.741%
5716220196

Pull #3261

github

aed2eb
fealebenpae
Merge remote-tracking branch 'origin/main' into yg/updated-marshaling

# Conflicts:
#	Realm/Realm/Handles/SharedRealmHandle.cs
Pull Request #3261: Use modern-er marshaling techniques

2029 of 2601 branches covered (78.01%)

Branch coverage included in aggregate %.

201 of 201 new or added lines in 21 files covered. (100.0%)

6246 of 7432 relevant lines covered (84.04%)

34048.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.09
/Realm/Realm/Handles/AsyncOpenTaskHandle.cs
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2019 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
using System;
20
using System.Collections.Concurrent;
21
using System.Runtime.InteropServices;
22

23
namespace Realms
24
{
25
    internal class AsyncOpenTaskHandle : StandaloneHandle
26
    {
27
        private static ConcurrentDictionary<AsyncOpenTaskHandle, bool> _handles = new();
1✔
28

29
        private static class NativeMethods
30
        {
31
            [DllImport(InteropConfig.DLL_NAME, EntryPoint = "realm_asyncopentask_destroy", CallingConvention = CallingConvention.Cdecl)]
32
            public static extern void destroy(IntPtr asyncTaskHandle);
33

34
            [DllImport(InteropConfig.DLL_NAME, EntryPoint = "realm_asyncopentask_cancel", CallingConvention = CallingConvention.Cdecl)]
35
            public static extern void cancel(AsyncOpenTaskHandle handle, out NativeException ex);
36

37
            [DllImport(InteropConfig.DLL_NAME, EntryPoint = "realm_asyncopentask_register_progress_notifier", CallingConvention = CallingConvention.Cdecl)]
38
            public static extern ulong register_progress_notifier(AsyncOpenTaskHandle handle, IntPtr token_ptr, out NativeException ex);
39

40
            [DllImport(InteropConfig.DLL_NAME, EntryPoint = "realm_asyncopentask_unregister_progress_notifier", CallingConvention = CallingConvention.Cdecl)]
41
            public static extern void unregister_progress_notifier(AsyncOpenTaskHandle handle, ulong token, out NativeException ex);
42
        }
43

44
        public AsyncOpenTaskHandle(IntPtr handle) : base(handle)
330✔
45
        {
46
            _handles.TryAdd(this, true);
330✔
47
        }
330✔
48

49
        public void Cancel()
50
        {
51
            NativeMethods.cancel(this, out var ex);
1✔
52
            ex.ThrowIfNecessary();
1✔
53
        }
1✔
54

55
        protected override void Unbind()
56
        {
57
            _handles.TryRemove(this, out _);
330✔
58

59
            NativeMethods.destroy(handle);
330✔
60
        }
330✔
61

62
        /// <summary>
63
        /// Cancels all in-flight async open tasks. This should only be used when the domain is being torn down.
64
        /// The case this handles is:
65
        /// 1. GetInstanceAsync.
66
        /// 2. Domain Reload wipes all coordinator caches.
67
        /// 3. AsyncOpen completes, calls back into managed (because s_can_call_managed is true again).
68
        /// 4. Undefined behavior as the state from before the domain reload is no longer valid.
69
        /// </summary>
70
        /// <remarks>This fixes the issue reported in https://github.com/realm/realm-dotnet/issues/3344.</remarks>
71
        public static void CancelInFlightTasks()
72
        {
73
            var keys = _handles.Keys;
×
74
            foreach (var value in keys)
×
75
            {
76
                value.Cancel();
×
77
            }
78
        }
×
79

80
        public ulong RegisterProgressNotifier(GCHandle managedHandle)
81
        {
82
            var token = NativeMethods.register_progress_notifier(this, GCHandle.ToIntPtr(managedHandle), out var ex);
3✔
83
            ex.ThrowIfNecessary();
3✔
84
            return token;
3✔
85
        }
86

87
        public void UnregisterProgressNotifier(ulong token)
88
        {
89
            NativeMethods.unregister_progress_notifier(this, token, out var ex);
×
90
            ex.ThrowIfNecessary();
×
91
        }
×
92
    }
93
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc