X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Threading.Tasks%2FTaskFactory_T.cs;h=0ac088c9058160dc52cc14bbc0d73ca6d066ea2c;hb=8bb9b4409d3f73fdf5ec2afc3b9add6bd33f712f;hp=0c4ba2a09263a74e61af5ef1db8b4d973f6d10f7;hpb=c133ae2dc82c0533f5790333a3c93b2635b9c43c;p=mono.git diff --git a/mcs/class/corlib/System.Threading.Tasks/TaskFactory_T.cs b/mcs/class/corlib/System.Threading.Tasks/TaskFactory_T.cs index 0c4ba2a0926..0ac088c9058 100644 --- a/mcs/class/corlib/System.Threading.Tasks/TaskFactory_T.cs +++ b/mcs/class/corlib/System.Threading.Tasks/TaskFactory_T.cs @@ -339,14 +339,13 @@ namespace System.Threading.Tasks throw new ArgumentOutOfRangeException ("creationOptions"); var tcs = new TaskCompletionSource (state, creationOptions); - var alreadyInvoked = false; + var alreadyInvoked = new AtomicBoolean (); var iar = beginMethod (l => { - alreadyInvoked = true; - InnerInvoke (tcs, endMethod, l); + if (alreadyInvoked.TryRelaxedSet ()) + InnerInvoke (tcs, endMethod, l); }, state); - if (iar != null && !alreadyInvoked && iar.CompletedSynchronously) { + if (iar != null && iar.CompletedSynchronously && alreadyInvoked.TryRelaxedSet ()) InnerInvoke (tcs, endMethod, iar); - } return tcs.Task; } @@ -377,14 +376,13 @@ namespace System.Threading.Tasks throw new ArgumentOutOfRangeException ("creationOptions"); var tcs = new TaskCompletionSource (state, creationOptions); - var alreadyInvoked = false; + var alreadyInvoked = new AtomicBoolean (); var iar = beginMethod (arg1, l => { - alreadyInvoked = true; - InnerInvoke (tcs, endMethod, l); + if (alreadyInvoked.TryRelaxedSet ()) + InnerInvoke (tcs, endMethod, l); }, state); - if (iar != null && !alreadyInvoked && iar.CompletedSynchronously) { + if (iar != null && iar.CompletedSynchronously && alreadyInvoked.TryRelaxedSet ()) InnerInvoke (tcs, endMethod, iar); - } return tcs.Task; } @@ -414,14 +412,13 @@ namespace System.Threading.Tasks throw new ArgumentOutOfRangeException ("creationOptions"); var tcs = new TaskCompletionSource (state, creationOptions); - var alreadyInvoked = false; + var alreadyInvoked = new AtomicBoolean (); var iar = beginMethod (arg1, arg2, l => { - alreadyInvoked = true; - InnerInvoke (tcs, endMethod, l); + if (alreadyInvoked.TryRelaxedSet ()) + InnerInvoke (tcs, endMethod, l); }, state); - if (iar != null && !alreadyInvoked && iar.CompletedSynchronously) { + if (iar != null && iar.CompletedSynchronously && alreadyInvoked.TryRelaxedSet ()) InnerInvoke (tcs, endMethod, iar); - } return tcs.Task; } @@ -452,14 +449,13 @@ namespace System.Threading.Tasks throw new ArgumentOutOfRangeException ("creationOptions"); var tcs = new TaskCompletionSource (state, creationOptions); - bool alreadyInvoked = false; + var alreadyInvoked = new AtomicBoolean (); var iar = beginMethod (arg1, arg2, arg3, l => { - alreadyInvoked = true; - InnerInvoke (tcs, endMethod, l); + if (alreadyInvoked.TryRelaxedSet ()) + InnerInvoke (tcs, endMethod, l); }, state); - if (iar != null && !alreadyInvoked && iar.CompletedSynchronously) { + if (iar != null && iar.CompletedSynchronously && alreadyInvoked.TryRelaxedSet ()) InnerInvoke (tcs, endMethod, iar); - } return tcs.Task; }