Skip to content

Commit c120dcd

Browse files
authored
Add mono_unity_gc_set_mode API to replace mono_unity_gc_enable/mono_unity_gc_disable/mono_unity_gc_is_disabled (#1302)
1 parent fdc4fb5 commit c120dcd

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

mono/metadata/unity-utils.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,34 @@ mono_unity_get_unitytls_interface()
913913
}
914914

915915
// gc
916+
MONO_API void mono_unity_gc_set_mode(MonoGCMode mode)
917+
{
918+
#if HAVE_BDWGC_GC
919+
switch (mode)
920+
{
921+
case MONO_GC_MODE_ENABLED:
922+
if (GC_is_disabled())
923+
GC_enable();
924+
GC_set_disable_automatic_collection(FALSE);
925+
break;
926+
927+
case MONO_GC_MODE_DISABLED:
928+
if (!GC_is_disabled())
929+
GC_disable();
930+
break;
931+
932+
case MONO_GC_MODE_MANUAL:
933+
if (GC_is_disabled())
934+
GC_enable();
935+
GC_set_disable_automatic_collection(TRUE);
936+
break;
937+
}
938+
#else
939+
g_assert_not_reached ();
940+
#endif
941+
}
942+
943+
// Deprecated. Remove when Unity has switched to mono_unity_gc_set_mode
916944
MONO_API void mono_unity_gc_enable()
917945
{
918946
#if HAVE_BDWGC_GC
@@ -922,6 +950,7 @@ MONO_API void mono_unity_gc_enable()
922950
#endif
923951
}
924952

953+
// Deprecated. Remove when Unity has switched to mono_unity_gc_set_mode
925954
MONO_API void mono_unity_gc_disable()
926955
{
927956
#if HAVE_BDWGC_GC
@@ -931,6 +960,7 @@ MONO_API void mono_unity_gc_disable()
931960
#endif
932961
}
933962

963+
// Deprecated. Remove when Unity has switched to mono_unity_gc_set_mode
934964
MONO_API int mono_unity_gc_is_disabled()
935965
{
936966
#if HAVE_BDWGC_GC

mono/metadata/unity-utils.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,23 @@ MONO_API unitytls_interface_struct* mono_unity_get_unitytls_interface();
152152
MONO_API void mono_unity_install_unitytls_interface(unitytls_interface_struct* callbacks);
153153

154154
// gc
155+
typedef enum
156+
{
157+
MONO_GC_MODE_DISABLED = 0,
158+
MONO_GC_MODE_ENABLED = 1,
159+
MONO_GC_MODE_MANUAL = 2
160+
} MonoGCMode;
161+
162+
MONO_API void mono_unity_gc_set_mode(MonoGCMode mode);
163+
164+
// Deprecated. Remove when Unity has switched to mono_unity_gc_set_mode
155165
MONO_API void mono_unity_gc_enable();
166+
// Deprecated. Remove when Unity has switched to mono_unity_gc_set_mode
156167
MONO_API void mono_unity_gc_disable();
168+
// Deprecated. Remove when Unity has switched to mono_unity_gc_set_mode
157169
MONO_API int mono_unity_gc_is_disabled();
158170

171+
159172
//misc
160173
MonoAssembly* mono_unity_assembly_get_mscorlib();
161174
MonoImage* mono_unity_image_get_mscorlib();

0 commit comments

Comments
 (0)