X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fw32mutex-win32.c;h=f7a68c5c74bced5032da9b71b667236a2dff5d71;hb=HEAD;hp=6f967e8d3262a9e4e6f0e92910203d12171dd7a7;hpb=3319d6a5a753c3ded84c20a4ff2a0935a58fec21;p=mono.git diff --git a/mono/metadata/w32mutex-win32.c b/mono/metadata/w32mutex-win32.c index 6f967e8d326..f7a68c5c74b 100644 --- a/mono/metadata/w32mutex-win32.c +++ b/mono/metadata/w32mutex-win32.c @@ -1,5 +1,6 @@ -/* - * w32mutex-win32.c: Runtime support for managed Mutex on Win32 +/** + * \file + * Runtime support for managed Mutex on Win32 * * Author: * Ludovic Henry (luhenry@microsoft.com) @@ -11,6 +12,9 @@ #include #include +#include +#include + void mono_w32mutex_init (void) @@ -18,19 +22,28 @@ mono_w32mutex_init (void) } gpointer -ves_icall_System_Threading_Mutex_CreateMutex_internal (MonoBoolean owned, MonoString *name, MonoBoolean *created) +ves_icall_System_Threading_Mutex_CreateMutex_internal (MonoBoolean owned, MonoStringHandle name, MonoBoolean *created, MonoError *error) { HANDLE mutex; + error_init (error); + *created = TRUE; - if (!name) { + if (MONO_HANDLE_IS_NULL (name)) { + MONO_ENTER_GC_SAFE; mutex = CreateMutex (NULL, owned, NULL); + MONO_EXIT_GC_SAFE; } else { - mutex = CreateMutex (NULL, owned, mono_string_chars (name)); + uint32_t gchandle; + gunichar2 *uniname = mono_string_handle_pin_chars (name, &gchandle); + MONO_ENTER_GC_SAFE; + mutex = CreateMutex (NULL, owned, uniname); if (GetLastError () == ERROR_ALREADY_EXISTS) *created = FALSE; + MONO_EXIT_GC_SAFE; + mono_gchandle_free (gchandle); } return mutex; @@ -43,15 +56,24 @@ ves_icall_System_Threading_Mutex_ReleaseMutex_internal (gpointer handle) } gpointer -ves_icall_System_Threading_Mutex_OpenMutex_internal (MonoString *name, gint32 rights, gint32 *error) +ves_icall_System_Threading_Mutex_OpenMutex_internal (MonoStringHandle name, gint32 rights, gint32 *err, MonoError *error) { HANDLE ret; - *error = ERROR_SUCCESS; + error_init (error); + *err = ERROR_SUCCESS; - ret = OpenMutex (rights, FALSE, mono_string_chars (name)); + uint32_t gchandle = 0; + gunichar2 *uniname = NULL; + if (!MONO_HANDLE_IS_NULL (name)) + uniname = mono_string_handle_pin_chars (name, &gchandle); + MONO_ENTER_GC_SAFE; + ret = OpenMutex (rights, FALSE, uniname); if (!ret) - *error = GetLastError (); + *err = GetLastError (); + MONO_EXIT_GC_SAFE; + if (gchandle != 0) + mono_gchandle_free (gchandle); return ret; }