Merge pull request #3548 from cmp-/fix-sgen-resume-thread-win32
[mono.git] / mono / metadata / w32mutex-win32.c
1 /*
2  * w32mutex-win32.c: Runtime support for managed Mutex 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 "w32mutex.h"
11
12 #include <windows.h>
13 #include <winbase.h>
14
15 void
16 mono_w32mutex_init (void)
17 {
18 }
19
20 gpointer
21 ves_icall_System_Threading_Mutex_CreateMutex_internal (MonoBoolean owned, MonoString *name, MonoBoolean *created)
22 {
23         HANDLE mutex;
24
25         *created = TRUE;
26
27         if (!name) {
28                 mutex = CreateMutex (NULL, owned, NULL);
29         } else {
30                 mutex = CreateMutex (NULL, owned, mono_string_chars (name));
31
32                 if (GetLastError () == ERROR_ALREADY_EXISTS)
33                         *created = FALSE;
34         }
35
36         return mutex;
37 }
38
39 MonoBoolean
40 ves_icall_System_Threading_Mutex_ReleaseMutex_internal (gpointer handle)
41 {
42         return ReleaseMutex (handle);
43 }
44
45 gpointer
46 ves_icall_System_Threading_Mutex_OpenMutex_internal (MonoString *name, gint32 rights, gint32 *error)
47 {
48         HANDLE ret;
49
50         *error = ERROR_SUCCESS;
51
52         ret = OpenMutex (rights, FALSE, mono_string_chars (name));
53         if (!ret)
54                 *error = GetLastError ();
55
56         return ret;
57 }