Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/mono/mono/metadata/sgen-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ volatile gboolean mono_bridge_processing_in_progress = FALSE;
*/
void
mono_gc_wait_for_bridge_processing (void)
{
MONO_ENTER_GC_UNSAFE;
mono_gc_wait_for_bridge_processing_internal ();
MONO_EXIT_GC_UNSAFE;
}

void
mono_gc_wait_for_bridge_processing_internal (void)
{
if (!mono_bridge_processing_in_progress)
return;
Expand Down Expand Up @@ -738,6 +746,11 @@ mono_gc_wait_for_bridge_processing (void)
{
}

void
mono_gc_wait_for_bridge_processing_internal (void)
{
}

MonoGCBridgeObjectKind
sgen_bridge_class_kind (MonoClass *klass)
{
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/sgen-bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ typedef struct {
*/
MONO_API void mono_gc_register_bridge_callbacks (MonoGCBridgeCallbacks *callbacks);

MONO_API void mono_gc_wait_for_bridge_processing (void);
MONO_API MONO_RT_EXTERNAL_ONLY void mono_gc_wait_for_bridge_processing (void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this MONO_RT_EXTERNAL_ONLY thing is to mark it as something that should only be called externally, not by the runtime itself? Is there some static checking that prevents such calls?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It expands to an __attribute__((deprecated)) when it's compiled inside the runtime, so we get a build error.

the general pattern we've been following with GC Unsafe transitions in MONO_API functions is that we add an _internal vesion which doesn't do the transition (because inside the runtime we're in GC Unsafe mode most of the time and do transitions explicitly), and an external-only API function that performs the transition explicitly because they are primarily called from outside the runtime which is mostly in GC Safe mode. (transitions to enter unsafe are ok to nest, so it would be harmless to dispense with the _internal function, but it's a bit nicer to avoid the extraneous function call)


MONO_END_DECLS

Expand Down
5 changes: 4 additions & 1 deletion src/mono/mono/metadata/sgen-client-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,13 @@ sgen_client_bridge_processing_stw_step (void)
sgen_bridge_processing_stw_step ();
}

void
mono_gc_wait_for_bridge_processing_internal (void);

static void G_GNUC_UNUSED
sgen_client_bridge_wait_for_processing (void)
{
mono_gc_wait_for_bridge_processing ();
mono_gc_wait_for_bridge_processing_internal ();
}

static void G_GNUC_UNUSED
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/sgen-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -2848,7 +2848,7 @@ sgen_client_ensure_weak_gchandles_accessible (void)
* should wait for bridge processing but would fail to do so.
*/
if (G_UNLIKELY (mono_bridge_processing_in_progress))
mono_gc_wait_for_bridge_processing ();
mono_gc_wait_for_bridge_processing_internal ();
}

void*
Expand Down