2 // System.Threading.AutoResetEvent.cs
5 // Dick Porter (dick@ximian.com)
6 // Veronica De Santis (veron78@interfree.it)
8 // (C) Ximian, Inc. http://www.ximian.com
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System
.Runtime
.CompilerServices
;
36 using Microsoft
.Win32
.SafeHandles
;
39 using System
.Security
.AccessControl
;
43 namespace System
.Threading
45 internal static class NativeEventCalls
47 public unsafe static IntPtr
CreateEvent_internal (bool manual
, bool initial
, string name
, out int errorCode
)
49 // FIXME check for embedded nuls in name
50 fixed (char *fixed_name
= name
)
51 return CreateEvent_icall (manual
, initial
, fixed_name
, name
?.Length
?? 0, out errorCode
);
54 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
55 private unsafe static extern IntPtr
CreateEvent_icall (bool manual
, bool initial
, char *name
, int name_length
, out int errorCode
);
57 public static bool SetEvent (SafeWaitHandle handle
)
61 handle
.DangerousAddRef (ref release
);
62 return SetEvent_internal (handle
.DangerousGetHandle ());
65 handle
.DangerousRelease ();
69 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
70 static extern bool SetEvent_internal(IntPtr handle
);
72 public static bool ResetEvent (SafeWaitHandle handle
)
76 handle
.DangerousAddRef (ref release
);
77 return ResetEvent_internal (handle
.DangerousGetHandle ());
80 handle
.DangerousRelease ();
84 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
85 static extern bool ResetEvent_internal(IntPtr handle
);
87 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
88 public static extern void CloseEvent_internal (IntPtr handle
);
91 public unsafe static IntPtr
OpenEvent_internal (string name
, EventWaitHandleRights rights
, out int errorCode
)
93 // FIXME check for embedded nuls in name
94 fixed (char *fixed_name
= name
)
95 return OpenEvent_icall (fixed_name
, name
?.Length
?? 0, rights
, out errorCode
);
98 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
99 private unsafe static extern IntPtr
OpenEvent_icall (char *name
, int name_length
, EventWaitHandleRights rights
, out int errorCode
);