Revert the CER-like changes made to SpinLock.Enter method and document the problem.
[mono.git] / mcs / class / corlib / System.Threading / LazyInitializer.cs
index df6d7cd0fe8b0163c83104917c94971769dfeaf8..9b4ada957ac2836b4c450ea46af47b58d27b4332 100644 (file)
@@ -1,4 +1,3 @@
-#if NET_4_0 || BOOTSTRAP_NET_4_0
 // 
 // LazyInitializer.cs
 //  
@@ -25,6 +24,8 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
+#if NET_4_0 || BOOTSTRAP_NET_4_0
+
 using System;
 
 namespace System.Threading
@@ -38,7 +39,8 @@ namespace System.Threading
                
                public static T EnsureInitialized<T> (ref T target, Func<T> initFunc) where T : class
                {
-                       Interlocked.CompareExchange (ref target, initFunc (), null);
+                       if (target == null)
+                               Interlocked.CompareExchange (ref target, initFunc (), null);
                        
                        return target;
                }