X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Threading%2FEventWaitHandle.cs;h=599a37bfe1ec14a2c5436631123fe9755fd01b6b;hb=f6fa8f03593266cd8d9c85771eb7db28eda85fa3;hp=e1ac46fc16051a35de8f2eef74125ab848f58bd4;hpb=4eb352bcb3ef7a71dc9ab62c5cd2d5e7598619f7;p=mono.git diff --git a/mcs/class/corlib/System.Threading/EventWaitHandle.cs b/mcs/class/corlib/System.Threading/EventWaitHandle.cs index e1ac46fc160..599a37bfe1e 100644 --- a/mcs/class/corlib/System.Threading/EventWaitHandle.cs +++ b/mcs/class/corlib/System.Threading/EventWaitHandle.cs @@ -27,55 +27,70 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#if NET_2_0 - -using System.Security.AccessControl; using System.IO; +using System.Runtime.InteropServices; +using System.Security.AccessControl; namespace System.Threading { + [ComVisible (true)] public class EventWaitHandle : WaitHandle { private EventWaitHandle (IntPtr handle) { Handle = handle; } + + static bool IsManualReset (EventResetMode mode) + { + if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset)) + throw new ArgumentException ("mode"); + return (mode == EventResetMode.ManualReset); + } public EventWaitHandle (bool initialState, EventResetMode mode) { bool created; - - Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, null, out created); + bool manual = IsManualReset (mode); + Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, null, out created); } +#if !MOBILE + public EventWaitHandle (bool initialState, EventResetMode mode, string name) { bool created; - - Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out created); + bool manual = IsManualReset (mode); + Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out created); } public EventWaitHandle (bool initialState, EventResetMode mode, string name, out bool createdNew) { - Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out createdNew); + bool manual = IsManualReset (mode); + Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew); } - - [MonoTODO ("Implement access control")] + + + [MonoTODO ("Use access control in CreateEvent_internal")] public EventWaitHandle (bool initialState, EventResetMode mode, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity) { - Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out createdNew); + bool manual = IsManualReset (mode); + Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew); } - [MonoTODO] public EventWaitHandleSecurity GetAccessControl () { - throw new NotImplementedException (); + return new EventWaitHandleSecurity (SafeWaitHandle, + AccessControlSections.Owner | + AccessControlSections.Group | + AccessControlSections.Access); + } - + public static EventWaitHandle OpenExisting (string name) { return(OpenExisting (name, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify)); @@ -105,27 +120,116 @@ namespace System.Threading return(new EventWaitHandle (handle)); } + + public static bool TryOpenExisting (string name, out EventWaitHandle result) + { + return TryOpenExisting ( + name, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, out result); + } + + public static bool TryOpenExisting (string name, EventWaitHandleRights rights, + out EventWaitHandle result) + { + if (name == null) { + throw new ArgumentNullException ("name"); + } + if ((name.Length == 0) || (name.Length > 260)) { + throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260].")); + } + + MonoIOError error; + IntPtr handle = NativeEventCalls.OpenEvent_internal (name, rights, out error); + if (handle == (IntPtr)null) { + result = null; + return false; + } + + result = new EventWaitHandle (handle); + return true; + } +#else + public EventWaitHandle (bool initialState, EventResetMode mode, string name) + { + throw new NotSupportedException (); + } + + public EventWaitHandle (bool initialState, EventResetMode mode, + string name, out bool createdNew) + { + throw new NotSupportedException (); + } + + public EventWaitHandle (bool initialState, EventResetMode mode, + string name, out bool createdNew, + EventWaitHandleSecurity eventSecurity) + { + throw new NotSupportedException (); + } + + public static EventWaitHandle OpenExisting (string name) + { + throw new NotSupportedException (); + } + + public static EventWaitHandle OpenExisting (string name, EventWaitHandleRights rights) + { + throw new NotSupportedException (); + } + + public static bool TryOpenExisting (string name, out EventWaitHandle result) + { + throw new NotSupportedException (); + } + + public static bool TryOpenExisting (string name, EventWaitHandleRights rights, + out EventWaitHandle result) + { + throw new NotSupportedException (); + } +#endif + public bool Reset () { - CheckDisposed (); + /* This needs locking since another thread could dispose the handle */ + lock (this) { + CheckDisposed (); - return (NativeEventCalls.ResetEvent_internal (Handle)); + return (NativeEventCalls.ResetEvent_internal (Handle)); + } } public bool Set () { - CheckDisposed (); + lock (this) { + CheckDisposed (); - return (NativeEventCalls.SetEvent_internal (Handle)); + return (NativeEventCalls.SetEvent_internal (Handle)); + } } - [MonoTODO] + internal void CheckDisposed () + { + if (disposed) + throw new ObjectDisposedException (GetType ().FullName); + } + + bool disposed; + protected override void Dispose(bool explicitDisposing) + { + base.Dispose (explicitDisposing); + disposed = true; + } + +#if !NET_2_1 public void SetAccessControl (EventWaitHandleSecurity eventSecurity) { - throw new NotImplementedException (); + if (null == eventSecurity) + throw new ArgumentNullException ("eventSecurity"); + + eventSecurity.PersistModifications (SafeWaitHandle); + } +#endif } } - -#endif