Skip to content

Commit 8d69ad8

Browse files
Move IsMainThread to AtomicNET and make it accessible
1 parent e139000 commit 8d69ad8

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎Script/AtomicNET/AtomicNET/Core/AtomicNET.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ public static void RunGC()
6767
NativeCore.RunGC();
6868
}
6969

70+
/// <summary>
71+
/// Returns true if called on main engine thread, false if on another thread
72+
/// </summary>
73+
public static bool IsMainThread()
74+
{
75+
return csi_AtomicEngine_IsMainThread();
76+
}
77+
7078
[DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
7179
private static extern uint csi_Atomic_AtomicNET_StringToStringHash(string name);
7280

@@ -131,6 +139,10 @@ public static void Initialize()
131139
[DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
132140
private static extern IntPtr csi_Atomic_NETCore_Initialize(EventDispatchDelegate eventDispatch, UpdateDispatchDelegate updateDispatch, RefCountedDeletedDelegate refCountedDeleted, ThrowManagedExceptionDelegate throwManagedException);
133141

142+
[DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
143+
[return: MarshalAs(UnmanagedType.I1)]
144+
private static extern bool csi_AtomicEngine_IsMainThread();
145+
134146
private static Context context;
135147
private static Dictionary<Type, AObject> subSystems = new Dictionary<Type, AObject>();
136148

‎Script/AtomicNET/AtomicNET/Core/NativeCore.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,6 @@ public static Type GetNativeAncestorType(Type type)
444444
[DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
445445
internal static extern void csi_AtomicEngine_ReleaseSilent(IntPtr refCounted);
446446

447-
[DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
448-
[return: MarshalAs(UnmanagedType.I1)]
449-
internal static extern bool csi_AtomicEngine_IsMainThread();
450-
451447
internal struct EventSubscription
452448
{
453449
public WeakReference<AObject> Receiver;

‎Script/AtomicNET/AtomicNET/Core/RefCounted.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ override protected bool ReleaseHandle()
3535
}
3636

3737
// We can be called from Dispose in main thread or from finalizers, which aren't in the main thread
38-
if (NativeCore.csi_AtomicEngine_IsMainThread())
38+
if (AtomicNET.IsMainThread())
3939
{
4040
NativeCore.csi_AtomicEngine_ReleaseRef(handle);
4141
}

0 commit comments

Comments
 (0)