Skip to content

Commit a961e4a

Browse files
Remove GetInstanceIfCreated and use Instance everywhere
Remove the defensive null checks in bridge processing. If bridge processing is being called, the instance must already exist since objects need to be registered for bridge processing to happen. Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
1 parent fabcb09 commit a961e4a

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

src/Mono.Android/Microsoft.Android.Runtime/ManagedValueManager.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class ManagedValueManager : JniRuntime.JniValueManager
3232
static Lazy<ManagedValueManager> s_instance = new (() => new ManagedValueManager ());
3333

3434
public static ManagedValueManager Instance => s_instance.Value;
35-
36-
static ManagedValueManager? GetInstanceIfCreated () => s_instance.IsValueCreated ? s_instance.Value : null;
3735

3836
unsafe ManagedValueManager ()
3937
{
@@ -444,24 +442,13 @@ static unsafe void BridgeProcessingFinished (MarkCrossReferencesArgs* mcr)
444442

445443
// Schedule cleanup of _registeredInstances on a thread pool thread.
446444
// The bridge thread must not take lock(_registeredInstances) — see deadlock notes.
447-
// Only schedule if instance exists (bridge processing typically implies registered objects exist).
448-
var instance = GetInstanceIfCreated ();
449-
if (instance != null) {
450-
Task.Run (instance.CollectPeers);
451-
}
445+
Task.Run (Instance.CollectPeers);
452446
}
453447

454448
static unsafe ReadOnlySpan<GCHandle> ProcessCollectedContexts (MarkCrossReferencesArgs* mcr)
455449
{
456450
List<GCHandle> handlesToFree = [];
457-
458-
// Bridge processing typically implies registered objects exist, but check defensively
459-
// to avoid creating the ManagedValueManager instance unnecessarily.
460-
ManagedValueManager? instance = GetInstanceIfCreated ();
461-
if (instance == null) {
462-
// No registered objects, nothing to process
463-
return ReadOnlySpan<GCHandle>.Empty;
464-
}
451+
ManagedValueManager instance = Instance;
465452

466453
for (int i = 0; (nuint)i < mcr->ComponentCount; i++) {
467454
StronglyConnectedComponent component = mcr->Components [i];

0 commit comments

Comments
 (0)