ICALL(MONIT_9, "try_enter_with_atomic_var", ves_icall_System_Threading_Monitor_Monitor_try_enter_with_atomic_var)
ICALL_TYPE(MUTEX, "System.Threading.Mutex", MUTEX_1)
-ICALL(MUTEX_1, "CreateMutex_internal(bool,string,bool&)", ves_icall_System_Threading_Mutex_CreateMutex_internal)
+HANDLES(ICALL(MUTEX_1, "CreateMutex_internal(bool,string,bool&)", ves_icall_System_Threading_Mutex_CreateMutex_internal))
ICALL(MUTEX_2, "OpenMutex_internal(string,System.Security.AccessControl.MutexRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Mutex_OpenMutex_internal)
ICALL(MUTEX_3, "ReleaseMutex_internal(intptr)", ves_icall_System_Threading_Mutex_ReleaseMutex_internal)
return mutex_handle_create (&mutex_handle, MONO_W32HANDLE_MUTEX, owned);
}
-static gpointer namedmutex_create (gboolean owned, const gunichar2 *name)
+static gpointer namedmutex_create (gboolean owned, const gchar *utf8_name)
{
gpointer handle;
- gchar *utf8_name;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating %s handle",
__func__, mono_w32handle_get_typename (MONO_W32HANDLE_NAMEDMUTEX));
/* w32 seems to guarantee that opening named objects can't race each other */
mono_w32handle_namespace_lock ();
- glong utf8_len = 0;
- utf8_name = g_utf16_to_utf8 (name, -1, NULL, &utf8_len, NULL);
+ glong utf8_len = strlen (utf8_name);
handle = mono_w32handle_namespace_search_handle (MONO_W32HANDLE_NAMEDMUTEX, utf8_name);
if (handle == INVALID_HANDLE_VALUE) {
handle = mutex_handle_create ((MonoW32HandleMutex*) &namedmutex_handle, MONO_W32HANDLE_NAMEDMUTEX, owned);
}
- g_free (utf8_name);
-
mono_w32handle_namespace_unlock ();
return handle;
}
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)
{
gpointer mutex;
+ error_init (error);
*created = TRUE;
/* Need to blow away any old errors here, because code tests
* was freshly created */
mono_w32error_set_last (ERROR_SUCCESS);
- if (!name) {
+ if (MONO_HANDLE_IS_NULL (name)) {
mutex = mutex_create (owned);
} else {
- mutex = namedmutex_create (owned, mono_string_chars (name));
+ gchar *utf8_name = mono_string_handle_to_utf8 (name, error);
+ return_val_if_nok (error, NULL);
+
+ mutex = namedmutex_create (owned, utf8_name);
if (mono_w32error_get_last () == ERROR_ALREADY_EXISTS)
*created = FALSE;
+ g_free (utf8_name);
}
return mutex;
#include <windows.h>
#include <winbase.h>
+#include <mono/metadata/handle.h>
+#include <mono/utils/mono-error-internals.h>
+
void
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;
#include <glib.h>
#include "object.h"
+#include "object-internals.h"
#include "w32handle-namespace.h"
void
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);
MonoBoolean
ves_icall_System_Threading_Mutex_ReleaseMutex_internal (gpointer handle);