remove GenericVectorTests from rsp (#17366)
[mono-project.git] / mono / metadata / w32mutex-win32.c
blob879bfeaa9c131a397d4475602f33f616e3c8f2d0
1 /**
2 * \file
3 * Runtime support for managed Mutex on Win32
5 * Author:
6 * Ludovic Henry (luhenry@microsoft.com)
8 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
9 */
11 #include "w32mutex.h"
13 #include <windows.h>
14 #include <winbase.h>
15 #include <mono/metadata/handle.h>
16 #include <mono/utils/mono-error-internals.h>
17 #include "icall-decl.h"
19 void
20 mono_w32mutex_init (void)
24 gpointer
25 ves_icall_System_Threading_Mutex_CreateMutex_icall (MonoBoolean owned, const gunichar2 *name,
26 gint32 name_length, MonoBoolean *created, MonoError *error)
28 HANDLE mutex;
30 *created = TRUE;
32 /* Need to blow away any old errors here, because code tests
33 * for ERROR_ALREADY_EXISTS on success (!) to see if a mutex
34 * was freshly created */
35 SetLastError (ERROR_SUCCESS);
37 MONO_ENTER_GC_SAFE;
38 mutex = CreateMutexW (NULL, owned, name);
39 if (name && GetLastError () == ERROR_ALREADY_EXISTS)
40 *created = FALSE;
41 MONO_EXIT_GC_SAFE;
43 return mutex;
46 MonoBoolean
47 ves_icall_System_Threading_Mutex_ReleaseMutex_internal (gpointer handle)
49 return ReleaseMutex (handle);
52 gpointer
53 ves_icall_System_Threading_Mutex_OpenMutex_icall (const gunichar2 *name, gint32 name_length,
54 gint32 rights, gint32 *win32error, MonoError *error)
56 HANDLE ret;
58 *win32error = ERROR_SUCCESS;
60 MONO_ENTER_GC_SAFE;
61 ret = OpenMutexW (rights, FALSE, name);
62 if (!ret)
63 *win32error = GetLastError ();
64 MONO_EXIT_GC_SAFE;
66 return ret;