Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Ferguson <scott.ferguson@unity3d.com>2020-01-24 17:57:48 +0300
committerScott Ferguson <scott.ferguson@unity3d.com>2020-01-24 17:57:48 +0300
commitdf63b279ada3d41e1e95e77c3bc2b4139d178f4b (patch)
tree0062814dd41471a08587cdb08ba3102244d39678 /Mono.Cecil/GenericInstanceType.cs
parent93aeae7f8f67e0d9899c41d252817bf12ec54086 (diff)
Improves thread safety of lazy initializations
The Interlocked.Exchange calls will ensure that the same object is returned from each call even under a race. That's not necessarily required, but it should also make sure that no write re-ordering issues occur on platforms that allow it. And it also makes the possibility of thread safety issues explicit.
Diffstat (limited to 'Mono.Cecil/GenericInstanceType.cs')
-rw-r--r--Mono.Cecil/GenericInstanceType.cs9
1 files changed, 7 insertions, 2 deletions
diff --git a/Mono.Cecil/GenericInstanceType.cs b/Mono.Cecil/GenericInstanceType.cs
index 8885850..745acd8 100644
--- a/Mono.Cecil/GenericInstanceType.cs
+++ b/Mono.Cecil/GenericInstanceType.cs
@@ -10,7 +10,7 @@
using System;
using System.Text;
-
+using System.Threading;
using Mono.Collections.Generic;
using MD = Mono.Cecil.Metadata;
@@ -26,7 +26,12 @@ namespace Mono.Cecil {
}
public Collection<TypeReference> GenericArguments {
- get { return arguments ?? (arguments = new Collection<TypeReference> ()); }
+ get {
+ if (arguments == null)
+ Interlocked.CompareExchange (ref arguments, new Collection<TypeReference> (), null);
+
+ return arguments;
+ }
}
public override TypeReference DeclaringType {