Merge pull request #3738 from lateralusX/jlorenss/win-api-family-support-libmonoruntime
[mono.git] / mono / metadata / w32semaphore-win32.c
1 /*
2  * w32semaphore-win32.c: Runtime support for managed Semaphore on Win32
3  *
4  * Author:
5  *      Ludovic Henry (luhenry@microsoft.com)
6  *
7  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
8  */
9
10 #include "w32semaphore.h"
11
12 #include <windows.h>
13 #include <winbase.h>
14
15 void
16 mono_w32semaphore_init (void)
17 {
18 }
19
20 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT | HAVE_UWP_WINAPI_SUPPORT)
21 gpointer
22 ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCount, gint32 maximumCount, MonoString *name, gint32 *error)
23
24         HANDLE sem;
25
26         sem = CreateSemaphore (NULL, initialCount, maximumCount, name ? mono_string_chars (name) : NULL);
27
28         *error = GetLastError ();
29
30         return sem;
31 }
32 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT | HAVE_UWP_WINAPI_SUPPORT) */
33
34 MonoBoolean
35 ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (gpointer handle, gint32 releaseCount, gint32 *prevcount)
36
37         return ReleaseSemaphore (handle, releaseCount, prevcount);
38 }
39
40 gpointer
41 ves_icall_System_Threading_Semaphore_OpenSemaphore_internal (MonoString *name, gint32 rights, gint32 *error)
42 {
43         HANDLE sem;
44
45         sem = OpenSemaphore (rights, FALSE, mono_string_chars (name));
46
47         *error = GetLastError ();
48
49         return sem;
50 }