Skip to content

Commit 08a20c8

Browse files
jechterUnityAlex
authored andcommitted
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 23711aa commit 08a20c8

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

mono/metadata/unity-utils.c

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

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

954+
// Deprecated. Remove when Unity has switched to mono_unity_gc_set_mode
926955
MONO_API void mono_unity_gc_disable()
927956
{
928957
#if HAVE_BOEHM_GC
@@ -932,6 +961,7 @@ MONO_API void mono_unity_gc_disable()
932961
#endif
933962
}
934963

964+
// Deprecated. Remove when Unity has switched to mono_unity_gc_set_mode
935965
MONO_API int mono_unity_gc_is_disabled()
936966
{
937967
#if HAVE_BOEHM_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)