Replace compGetMemArray uses
[platform/upstream/coreclr.git] / src / System.Private.CoreLib / shared / System / Threading / EventWaitHandle.cs
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 using System;
6 using System.IO;
7
8 namespace System.Threading
9 {
10     public partial class EventWaitHandle : WaitHandle
11     {
12         public EventWaitHandle(bool initialState, EventResetMode mode) :
13                         this(initialState, mode, null, out _)
14                 {
15                 }
16
17         public EventWaitHandle(bool initialState, EventResetMode mode, string name) :
18             this(initialState, mode, name, out _)
19         {
20         }
21
22         public EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew)
23         {
24             if (mode != EventResetMode.AutoReset && mode != EventResetMode.ManualReset)
25                 throw new ArgumentException(SR.Argument_InvalidFlag, nameof(mode));
26
27             CreateEventCore(initialState, mode, name, out createdNew);
28         }
29
30         public static EventWaitHandle OpenExisting(string name)
31         {
32             EventWaitHandle result;
33             switch (OpenExistingWorker(name, out result))
34             {
35                 case OpenExistingResult.NameNotFound:
36                     throw new WaitHandleCannotBeOpenedException();
37                 case OpenExistingResult.NameInvalid:
38                     throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
39                 case OpenExistingResult.PathNotFound:
40                     throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, name));
41                 default:
42                     return result;
43             }
44         }
45
46         public static bool TryOpenExisting(string name, out EventWaitHandle result)
47         {
48             return OpenExistingWorker(name, out result) == OpenExistingResult.Success;
49         }
50     }
51 }