// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System.Threading { using System; using System.Runtime.CompilerServices; using Microsoft.Singularity; using Microsoft.Singularity.V1.Threads; using Microsoft.Singularity.V1.Services; //| [CLSCompliant(false)] public sealed class AutoResetEvent : WaitHandle { private AutoResetEventHandle handle; //| public AutoResetEvent(bool initialState) { AutoResetEventHandle handleOnStack; if (!AutoResetEventHandle.Create(initialState, out handleOnStack)) { throw new HandleCreateException(); } handle = handleOnStack; } /// /// Finalizer is responsible for freeing handle that keeps corresponding /// kernel AutoResetEvent object live. /// ~AutoResetEvent() { if (this.handle.id != 0) { AutoResetEventHandle.Dispose(this.handle); this.handle = new AutoResetEventHandle(); } } //| public void Reset() { AutoResetEventHandle.Reset(handle); GC.KeepAlive(this); } //| public void Set() { AutoResetEventHandle.Set(handle); GC.KeepAlive(this); } //| public void SetAll() { AutoResetEventHandle.SetAll(handle); GC.KeepAlive(this); } internal void SetNoGC() { AutoResetEventHandle.SetNoGC(handle); GC.KeepAlive(this); } protected override SyncHandle Handle{ get { return handle; } } //| public override bool WaitOne(TimeSpan timeout) { bool b = SyncHandle.WaitOne(handle, timeout); GC.KeepAlive(this); return b; } //| public override bool WaitOne(SchedulerTime stop) { bool b = SyncHandle.WaitOne(handle, stop); GC.KeepAlive(this); return b; } //| public override bool WaitOne() { bool b = SyncHandle.WaitOne(handle); GC.KeepAlive(this); return b; } internal bool WaitOneNoGC() { bool b = SyncHandle.WaitOneNoGC(handle); GC.KeepAlive(this); return b; } //| protected override void Dispose(bool explicitDisposing) { if (handle.id != 0) { AutoResetEventHandle.Dispose(handle); handle = new AutoResetEventHandle(); } } } }