2008-03-05 09:52:00 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Microsoft Research Singularity
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// File: AutoResetEvent.cs
|
|
|
|
//
|
|
|
|
// Note:
|
|
|
|
//
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using Microsoft.Singularity;
|
|
|
|
using Microsoft.Singularity.Io;
|
|
|
|
using Microsoft.Singularity.Scheduling;
|
|
|
|
|
|
|
|
namespace System.Threading
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
///
|
|
|
|
/// <summary>
|
|
|
|
/// Event class implementing an event with auto reset symantics such event automatically
|
|
|
|
/// reset to non signaled state when single wait is satisfied
|
|
|
|
/// </summary>
|
|
|
|
///
|
2008-03-05 09:52:00 -05:00
|
|
|
[NoCCtor]
|
|
|
|
[CLSCompliant(false)]
|
|
|
|
public sealed class AutoResetEvent : WaitHandle
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
///
|
|
|
|
/// <summary>
|
|
|
|
/// Constructor
|
|
|
|
///</summary>
|
|
|
|
///
|
|
|
|
/// <param name="initialState">Initial state of an event true indciates that event is signaled</param>
|
|
|
|
///
|
|
|
|
public AutoResetEvent(bool initialState)
|
|
|
|
: base(initialState ? WaitHandle.SignalState.Signaled :
|
|
|
|
WaitHandle.SignalState.Unsignaled,
|
|
|
|
WaitHandle.SignalState.Unsignaled,
|
|
|
|
SpinLock.Types.AutoResetEvent)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
///
|
|
|
|
/// <summary>
|
|
|
|
/// Reset an event state to non signaled
|
|
|
|
///</summary>
|
|
|
|
///
|
2008-03-05 09:52:00 -05:00
|
|
|
[NoHeapAllocation]
|
|
|
|
public bool Reset()
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
// Make sure that we don't have any waiters and then change event state to unsignaled
|
|
|
|
// in all the cases
|
|
|
|
SignalAll (WaitHandle.SignalState.Unsignaled, WaitHandle.SignalState.Unsignaled);
|
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
///
|
|
|
|
/// <summary>
|
|
|
|
/// Wake up one waiter, if no waiters present set event into signaled state
|
|
|
|
///</summary>
|
|
|
|
///
|
2008-03-05 09:52:00 -05:00
|
|
|
[NoHeapAllocation]
|
|
|
|
public bool Set()
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
// Signal one waiter if present otherwise set event to signaled
|
|
|
|
SignalOne(WaitHandle.SignalState.Signaled);
|
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
///
|
|
|
|
/// <summary>
|
|
|
|
/// Wake up all waiters and if event is not signaled set it into signaled state
|
|
|
|
///</summary>
|
|
|
|
///
|
2008-03-05 09:52:00 -05:00
|
|
|
public bool SetAll()
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
SignalAll (WaitHandle.SignalState.Signaled,WaitHandle.SignalState.Unsignaled);
|
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|