From c6da68cfd7ded9333291fe37881d7d266cfa6acb Mon Sep 17 00:00:00 2001 From: Ryan Lucia Date: Wed, 26 Aug 2020 09:59:58 -0400 Subject: [PATCH] [mono] Add mono_assembly_decref, return value on both decref and addref (#41342) --- src/mono/mono/metadata/assembly-load-context.c | 2 +- src/mono/mono/metadata/assembly.c | 12 +++++++++--- src/mono/mono/metadata/metadata-internals.h | 8 ++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/mono/mono/metadata/assembly-load-context.c b/src/mono/mono/metadata/assembly-load-context.c index e933461..105609d 100644 --- a/src/mono/mono/metadata/assembly-load-context.c +++ b/src/mono/mono/metadata/assembly-load-context.c @@ -53,7 +53,7 @@ mono_alc_cleanup (MonoAssemblyLoadContext *alc) for (tmp = alc->loaded_assemblies; tmp; tmp = tmp->next) { MonoAssembly *assembly = (MonoAssembly *)tmp->data; g_slist_remove (domain->domain_assemblies, assembly); - mono_atomic_dec_i32 (&assembly->ref_count); + mono_assembly_decref (assembly); mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Unloading ALC [%p], removing assembly %s[%p] from domain_assemblies, ref_count=%d\n", alc, assembly->aname.name, assembly, assembly->ref_count); } mono_domain_assemblies_unlock (domain); diff --git a/src/mono/mono/metadata/assembly.c b/src/mono/mono/metadata/assembly.c index dcbfbf7..d24ff56 100644 --- a/src/mono/mono/metadata/assembly.c +++ b/src/mono/mono/metadata/assembly.c @@ -1308,10 +1308,16 @@ assemblyref_public_tok_checked (MonoImage *image, guint32 key_index, guint32 fla * The reference count is reduced every time the method mono_assembly_close() is * invoked. */ -void +gint32 mono_assembly_addref (MonoAssembly *assembly) { - mono_atomic_inc_i32 (&assembly->ref_count); + return mono_atomic_inc_i32 (&assembly->ref_count); +} + +gint32 +mono_assembly_decref (MonoAssembly *assembly) +{ + return mono_atomic_dec_i32 (&assembly->ref_count); } /* @@ -5057,7 +5063,7 @@ mono_assembly_close_except_image_pools (MonoAssembly *assembly) return FALSE; /* Might be 0 already */ - if (mono_atomic_dec_i32 (&assembly->ref_count) > 0) + if (mono_assembly_decref (assembly) > 0) return FALSE; MONO_PROFILER_RAISE (assembly_unloading, (assembly)); diff --git a/src/mono/mono/metadata/metadata-internals.h b/src/mono/mono/metadata/metadata-internals.h index c37d40f..4767deb 100644 --- a/src/mono/mono/metadata/metadata-internals.h +++ b/src/mono/mono/metadata/metadata-internals.h @@ -216,7 +216,7 @@ struct _MonoAssembly { * the additional reference, they can be freed at any time. * The ref_count is initially 0. */ - int ref_count; /* use atomic operations only */ + gint32 ref_count; /* use atomic operations only */ char *basedir; MonoAssemblyName aname; MonoImage *image; @@ -1011,10 +1011,14 @@ gboolean mono_metadata_generic_param_equal (MonoGenericParam *p1, MonoGenericParam *p2); void mono_dynamic_stream_reset (MonoDynamicStream* stream); -MONO_API void mono_assembly_addref (MonoAssembly *assembly); void mono_assembly_load_friends (MonoAssembly* ass); gboolean mono_assembly_has_skip_verification (MonoAssembly* ass); +MONO_API gint32 +mono_assembly_addref (MonoAssembly *assembly); +gint32 +mono_assembly_decref (MonoAssembly *assembly); + void mono_assembly_release_gc_roots (MonoAssembly *assembly); gboolean mono_assembly_close_except_image_pools (MonoAssembly *assembly); void mono_assembly_close_finish (MonoAssembly *assembly); -- 2.7.4