Merge pull request #2646 from ludovic-henry/fix-processwatch-dispose
[mono.git] / mcs / class / corlib / System.Threading / NativeEventCalls.cs
index c73cf248c0675fa46c5cdc6447f102fa753a19b7..b0320579bfa227ec3a8058fe50ab22774d6fbf6d 100644 (file)
 
 using System;
 using System.Runtime.CompilerServices;
+using Microsoft.Win32.SafeHandles;
 
-#if NET_2_0
+#if !MOBILE
 using System.Security.AccessControl;
 using System.IO;
 #endif
 
 namespace System.Threading 
 {
-       internal sealed class NativeEventCalls
+       internal static class NativeEventCalls
        {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public static extern IntPtr CreateEvent_internal(bool manual,bool initial,string name, out bool created);
 
+               public static bool SetEvent (SafeWaitHandle handle)
+               {
+                       bool release = false;
+                       try {
+                               handle.DangerousAddRef (ref release);
+                               return SetEvent_internal (handle.DangerousGetHandle ());
+                       } finally {
+                               if (release)
+                                       handle.DangerousRelease ();
+                       }
+               }
+
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public static extern bool SetEvent_internal(IntPtr handle);
+               static extern bool SetEvent_internal(IntPtr handle);
+
+               public static bool ResetEvent (SafeWaitHandle handle)
+               {
+                       bool release = false;
+                       try {
+                               handle.DangerousAddRef (ref release);
+                               return ResetEvent_internal (handle.DangerousGetHandle ());
+                       } finally {
+                               if (release)
+                                       handle.DangerousRelease ();
+                       }
+               }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public static extern bool ResetEvent_internal(IntPtr handle);
+               static extern bool ResetEvent_internal(IntPtr handle);
        
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public static extern void CloseEvent_internal (IntPtr handle);
 
-#if NET_2_0
+#if !MOBILE
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                public static extern IntPtr OpenEvent_internal (string name, EventWaitHandleRights rights, out MonoIOError error);
 #endif