Implemented fast version of ThreadLocal<T>.
[mono.git] / mcs / class / corlib / System.Threading / CancellationTokenSource.cs
index 12f59a5d190bc19f2dcea0a90b9676c88e005764..1d9411fb2c7fa7687f326e6bde25027fe7c30088 100644 (file)
@@ -24,7 +24,7 @@
 // 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
+#if NET_4_0 || MOBILE
 using System;
 using System.Collections.Generic;
 
@@ -33,8 +33,8 @@ namespace System.Threading
        
        public sealed class CancellationTokenSource : IDisposable
        {
-               volatile bool canceled;
-               volatile bool processed;
+               bool canceled;
+               bool processed;
                
                int currId = int.MinValue;
                
@@ -53,18 +53,18 @@ namespace System.Threading
                }
                
                // If parameter is true we throw exception as soon as they appear otherwise we aggregate them
-               public void Cancel (bool throwOnFirst)
+               public void Cancel (bool throwOnFirstException)
                {
                        canceled = true;
                        handle.Set ();
                        
                        List<Exception> exceptions = null;
-                       if (!throwOnFirst)
+                       if (!throwOnFirstException)
                                exceptions = new List<Exception> ();
                        
                        lock (callbacks) {
                                foreach (KeyValuePair<CancellationTokenRegistration, Action> item in callbacks) {
-                                       if (throwOnFirst) {
+                                       if (throwOnFirstException) {
                                                item.Value ();
                                        } else {
                                                try {
@@ -76,6 +76,7 @@ namespace System.Threading
                                }
                        }
                        
+                       Thread.MemoryBarrier ();
                        processed = true;
                        
                        if (exceptions != null && exceptions.Count > 0)
@@ -155,13 +156,7 @@ namespace System.Threading
                                sw.SpinOnce ();
                        
                }
-               
-               internal void ThrowIfCancellationRequested ()
-               {
-                       if (canceled)
-                               throw new OperationCanceledException (CreateToken ());
-               }
-               
+
                CancellationTokenRegistration GetTokenReg ()
                {
                        CancellationTokenRegistration registration