-#if NET_4_0 || BOOTSTRAP_NET_4_0
//
// CancellationTokenSource.cs
//
// 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;
using System.Collections.Generic;
namespace System.Threading
{
- public class CancellationTokenSource : IDisposable, ICancelableOperation
+ public sealed class CancellationTokenSource : IDisposable
{
- volatile bool canceled;
- volatile bool processed;
+ bool canceled;
+ bool processed;
int currId = int.MinValue;
ManualResetEvent handle = new ManualResetEvent (false);
-//#if USE_MONITOR
object syncRoot = new object ();
-//#endif
+
+ internal static readonly CancellationTokenSource NoneSource = new CancellationTokenSource ();
public void Cancel ()
{
}
}
+ Thread.MemoryBarrier ();
processed = true;
if (exceptions != null && exceptions.Count > 0)
public CancellationToken Token {
get {
- CancellationToken token = new CancellationToken (canceled);
- token.Source = this;
-
- return token;
+ return CreateToken ();
}
}
sw.SpinOnce ();
}
-
+
CancellationTokenRegistration GetTokenReg ()
{
CancellationTokenRegistration registration
return registration;
}
+
+ CancellationToken CreateToken ()
+ {
+ CancellationToken tk = new CancellationToken (canceled);
+ tk.Source = this;
+
+ return tk;
+ }
}
}
#endif