1 // ==++== 2 // 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // 5 // ==--== 6 /*============================================================ 7 ** 8 ** Class: SafeWaitHandle 9 ** 10 ** 11 ** A wrapper for Win32 events (mutexes, auto reset events, and 12 ** manual reset events). Used by WaitHandle. 13 ** 14 ** 15 ===========================================================*/ 16 17 using System; 18 using System.Security; 19 using System.Security.Permissions; 20 using System.Runtime.InteropServices; 21 using System.Runtime.CompilerServices; 22 using System.Runtime.ConstrainedExecution; 23 using System.Runtime.Versioning; 24 using Microsoft.Win32; 25 using System.Threading; 26 27 namespace Microsoft.Win32.SafeHandles { 28 29 [System.Security.SecurityCritical] // auto-generated_required 30 public sealed class SafeWaitHandle : SafeHandleZeroOrMinusOneIsInvalid 31 { 32 // Called by P/Invoke marshaler SafeWaitHandle()33 private SafeWaitHandle() : base(true) 34 { 35 } 36 37 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] SafeWaitHandle(IntPtr existingHandle, bool ownsHandle)38 public SafeWaitHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) 39 { 40 SetHandle(existingHandle); 41 } 42 43 [System.Security.SecurityCritical] 44 [ResourceExposure(ResourceScope.Machine)] 45 [ResourceConsumption(ResourceScope.Machine)] ReleaseHandle()46 override protected bool ReleaseHandle() 47 { 48 #if MONO 49 NativeEventCalls.CloseEvent_internal (handle); 50 return true; 51 #else 52 return Win32Native.CloseHandle(handle); 53 #endif 54 } 55 } 56 } 57