Skip to content

Commit

Permalink
Remove Interlocked.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaanstra committed Nov 3, 2023
1 parent 73d5e29 commit f0659d4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/cswinrt/strings/WinRT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public static unsafe (IObjectReference obj, int hr) GetActivationFactory(string

internal class BaseActivationFactory
{
private Tuple<ObjectReference<IActivationFactoryVftbl>, IntPtr> _IActivationFactory;
private volatile Tuple<ObjectReference<IActivationFactoryVftbl>, IntPtr> _IActivationFactory;

public ObjectReference<IActivationFactoryVftbl> Value
{
Expand All @@ -508,7 +508,7 @@ public ObjectReference<IActivationFactoryVftbl> Value
}

var newFactory = InitializeFactory();
Interlocked.CompareExchange(ref _IActivationFactory, newFactory, existingInstance);
_IActivationFactory = newFactory;
return newFactory.Item1;
}
}
Expand Down Expand Up @@ -580,6 +580,10 @@ public unsafe ObjectReference<I> _ActivateInstance<I>()
}
}

#if NET
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2091:RequiresUnreferencedCode",
Justification = "No members of the generic type are dynamically accessed in this code path.")]
#endif
public ObjectReference<I> _As<I>() => Value.As<I>();
public IObjectReference _As(Guid iid) => Value.As<WinRT.Interop.IUnknownVftbl>(iid);
}
Expand Down Expand Up @@ -608,12 +612,14 @@ public static ObjectReference<I> ActivateInstance<
internal class BaseFactory
{

private Tuple<IObjectReference, IntPtr> _factory;
private volatile Tuple<IObjectReference, IntPtr> _factory;

public IObjectReference Value
#else
internal class BaseFactory<I>
{
private Tuple<ObjectReference<I>, IntPtr> _factory;
private volatile Tuple<ObjectReference<I>, IntPtr> _factory;

public ObjectReference<I> Value
#endif
{
Expand All @@ -626,7 +632,7 @@ public ObjectReference<I> Value
}

var newFactory = InitializeFactory();
Interlocked.CompareExchange(ref _factory, newFactory, existingInstance);
_factory = newFactory;
return newFactory.Item1;
}
}
Expand All @@ -645,7 +651,7 @@ public BaseFactory(string namespaceName, string typeName, Guid interfaceGuid)
#if NET
private Tuple<IObjectReference, IntPtr> InitializeFactory()
#else
private Tuple<IObjectReference, IntPtr> InitializeFactory()
private Tuple<ObjectReference<I>, IntPtr> InitializeFactory()
#endif
{
// Prefer the RoGetActivationFactory HRESULT failure over the LoadLibrary/etc. failure
Expand Down

0 comments on commit f0659d4

Please sign in to comment.