X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fw32mutex-unix.c;h=a39f5ca276163804a73af82022d485a634a10562;hb=c1086268ba833338bd33ea268f453ebcc063c7bd;hp=fbf1f6177a8bcb06ce95bf8b5e94b8785144b0f3;hpb=f16c0866a83499c11b622bcc9c7fe5ea4020062a;p=mono.git diff --git a/mono/metadata/w32mutex-unix.c b/mono/metadata/w32mutex-unix.c index fbf1f6177a8..a39f5ca2761 100644 --- a/mono/metadata/w32mutex-unix.c +++ b/mono/metadata/w32mutex-unix.c @@ -16,7 +16,7 @@ #include "mono/metadata/object-internals.h" #include "mono/utils/mono-logger-internals.h" #include "mono/utils/mono-threads.h" -#include "mono/utils/w32handle.h" +#include "mono/metadata/w32handle.h" typedef struct { MonoNativeThreadId tid; @@ -59,19 +59,19 @@ thread_disown_mutex (MonoInternalThread *internal, gpointer handle) } static gboolean -mutex_handle_own (gpointer handle, MonoW32HandleType type, guint32 *statuscode) +mutex_handle_own (gpointer handle, MonoW32HandleType type, gboolean *abandoned) { MonoW32HandleMutex *mutex_handle; - *statuscode = WAIT_OBJECT_0; + *abandoned = FALSE; if (!mono_w32handle_lookup (handle, type, (gpointer *)&mutex_handle)) { - g_warning ("%s: error looking up %s handle %p", __func__, mono_w32handle_ops_typename (type), handle); + g_warning ("%s: error looking up %s handle %p", __func__, mono_w32handle_get_typename (type), handle); return FALSE; } mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: owning %s handle %p, before: [tid: %p, recursion: %d], after: [tid: %p, recursion: %d], abandoned: %s", - __func__, mono_w32handle_ops_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion, (gpointer) pthread_self (), mutex_handle->recursion + 1, mutex_handle->abandoned ? "true" : "false"); + __func__, mono_w32handle_get_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion, (gpointer) pthread_self (), mutex_handle->recursion + 1, mutex_handle->abandoned ? "true" : "false"); if (mutex_handle->recursion != 0) { g_assert (pthread_equal (pthread_self (), mutex_handle->tid)); @@ -85,7 +85,7 @@ mutex_handle_own (gpointer handle, MonoW32HandleType type, guint32 *statuscode) if (mutex_handle->abandoned) { mutex_handle->abandoned = FALSE; - *statuscode = WAIT_ABANDONED_0; + *abandoned = TRUE; } mono_w32handle_set_signal_state (handle, FALSE, FALSE); @@ -99,20 +99,20 @@ mutex_handle_is_owned (gpointer handle, MonoW32HandleType type) MonoW32HandleMutex *mutex_handle; if (!mono_w32handle_lookup (handle, type, (gpointer *)&mutex_handle)) { - g_warning ("%s: error looking up %s handle %p", __func__, mono_w32handle_ops_typename (type), handle); + g_warning ("%s: error looking up %s handle %p", __func__, mono_w32handle_get_typename (type), handle); return FALSE; } mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: testing ownership %s handle %p", - __func__, mono_w32handle_ops_typename (type), handle); + __func__, mono_w32handle_get_typename (type), handle); if (mutex_handle->recursion > 0 && pthread_equal (mutex_handle->tid, pthread_self ())) { mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: %s handle %p owned by %p", - __func__, mono_w32handle_ops_typename (type), handle, (gpointer) pthread_self ()); + __func__, mono_w32handle_get_typename (type), handle, (gpointer) pthread_self ()); return TRUE; } else { mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: %s handle %p not owned by %p, tid: %p recursion: %d", - __func__, mono_w32handle_ops_typename (type), handle, (gpointer) pthread_self (), (gpointer) mutex_handle->tid, mutex_handle->recursion); + __func__, mono_w32handle_get_typename (type), handle, (gpointer) pthread_self (), (gpointer) mutex_handle->tid, mutex_handle->recursion); return FALSE; } } @@ -122,9 +122,9 @@ static void mutex_signal(gpointer handle) ves_icall_System_Threading_Mutex_ReleaseMutex_internal (handle); } -static gboolean mutex_own (gpointer handle, guint32 *statuscode) +static gboolean mutex_own (gpointer handle, gboolean *abandoned) { - return mutex_handle_own (handle, MONO_W32HANDLE_MUTEX, statuscode); + return mutex_handle_own (handle, MONO_W32HANDLE_MUTEX, abandoned); } static gboolean mutex_is_owned (gpointer handle) @@ -139,9 +139,9 @@ static void namedmutex_signal (gpointer handle) } /* NB, always called with the shared handle lock held */ -static gboolean namedmutex_own (gpointer handle, guint32 *statuscode) +static gboolean namedmutex_own (gpointer handle, gboolean *abandoned) { - return mutex_handle_own (handle, MONO_W32HANDLE_NAMEDMUTEX, statuscode); + return mutex_handle_own (handle, MONO_W32HANDLE_NAMEDMUTEX, abandoned); } static gboolean namedmutex_is_owned (gpointer handle) @@ -161,12 +161,12 @@ static void mutex_handle_prewait (gpointer handle, MonoW32HandleType type) if (!mono_w32handle_lookup (handle, type, (gpointer *)&mutex_handle)) { g_warning ("%s: error looking up %s handle %p", - __func__, mono_w32handle_ops_typename (type), handle); + __func__, mono_w32handle_get_typename (type), handle); return; } mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: pre-waiting %s handle %p, owned? %s", - __func__, mono_w32handle_ops_typename (type), handle, mutex_handle->recursion != 0 ? "true" : "false"); + __func__, mono_w32handle_get_typename (type), handle, mutex_handle->recursion != 0 ? "true" : "false"); } /* The shared state is not locked when prewait methods are called */ @@ -264,8 +264,7 @@ mono_w32mutex_init (void) static gpointer mutex_handle_create (MonoW32HandleMutex *mutex_handle, MonoW32HandleType type, gboolean owned) { gpointer handle; - int thr_ret; - guint32 statuscode; + gboolean abandoned; mutex_handle->tid = 0; mutex_handle->recursion = 0; @@ -274,24 +273,22 @@ static gpointer mutex_handle_create (MonoW32HandleMutex *mutex_handle, MonoW32Ha handle = mono_w32handle_new (type, mutex_handle); if (handle == INVALID_HANDLE_VALUE) { g_warning ("%s: error creating %s handle", - __func__, mono_w32handle_ops_typename (type)); + __func__, mono_w32handle_get_typename (type)); SetLastError (ERROR_GEN_FAILURE); return NULL; } - thr_ret = mono_w32handle_lock_handle (handle); - g_assert (thr_ret == 0); + mono_w32handle_lock_handle (handle); if (owned) - mutex_handle_own (handle, type, &statuscode); + mutex_handle_own (handle, type, &abandoned); else mono_w32handle_set_signal_state (handle, TRUE, FALSE); - thr_ret = mono_w32handle_unlock_handle (handle); - g_assert (thr_ret == 0); + mono_w32handle_unlock_handle (handle); mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: created %s handle %p", - __func__, mono_w32handle_ops_typename (type), handle); + __func__, mono_w32handle_get_typename (type), handle); return handle; } @@ -300,7 +297,7 @@ static gpointer mutex_create (gboolean owned) { MonoW32HandleMutex mutex_handle; mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating %s handle", - __func__, mono_w32handle_ops_typename (MONO_W32HANDLE_MUTEX)); + __func__, mono_w32handle_get_typename (MONO_W32HANDLE_MUTEX)); return mutex_handle_create (&mutex_handle, MONO_W32HANDLE_MUTEX, owned); } @@ -310,7 +307,7 @@ static gpointer namedmutex_create (gboolean owned, const gunichar2 *name) gchar *utf8_name; mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating %s handle", - __func__, mono_w32handle_ops_typename (MONO_W32HANDLE_NAMEDMUTEX)); + __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 (); @@ -374,7 +371,6 @@ ves_icall_System_Threading_Mutex_ReleaseMutex_internal (gpointer handle) MonoW32HandleType type; MonoW32HandleMutex *mutex_handle; pthread_t tid; - int thr_ret; gboolean ret; if (handle == NULL) { @@ -393,15 +389,14 @@ ves_icall_System_Threading_Mutex_ReleaseMutex_internal (gpointer handle) if (!mono_w32handle_lookup (handle, type, (gpointer *)&mutex_handle)) { g_warning ("%s: error looking up %s handle %p", - __func__, mono_w32handle_ops_typename (type), handle); + __func__, mono_w32handle_get_typename (type), handle); return FALSE; } mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: releasing %s handle %p, tid: %p recursion: %d", - __func__, mono_w32handle_ops_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion); + __func__, mono_w32handle_get_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion); - thr_ret = mono_w32handle_lock_handle (handle); - g_assert (thr_ret == 0); + mono_w32handle_lock_handle (handle); tid = pthread_self (); @@ -412,7 +407,7 @@ ves_icall_System_Threading_Mutex_ReleaseMutex_internal (gpointer handle) ret = FALSE; mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: we don't own %s handle %p (owned by %ld, me %ld)", - __func__, mono_w32handle_ops_typename (type), handle, (long)mutex_handle->tid, (long)tid); + __func__, mono_w32handle_get_typename (type), handle, (long)mutex_handle->tid, (long)tid); } else { ret = TRUE; @@ -423,15 +418,14 @@ ves_icall_System_Threading_Mutex_ReleaseMutex_internal (gpointer handle) thread_disown_mutex (mono_thread_internal_current (), handle); mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unlocking %s handle %p, tid: %p recusion : %d", - __func__, mono_w32handle_ops_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion); + __func__, mono_w32handle_get_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion); mutex_handle->tid = 0; mono_w32handle_set_signal_state (handle, TRUE, FALSE); } } - thr_ret = mono_w32handle_unlock_handle (handle); - g_assert (thr_ret == 0); + mono_w32handle_unlock_handle (handle); return ret; } @@ -492,7 +486,6 @@ mono_w32mutex_abandon (void) MonoW32HandleMutex *mutex_handle; MonoNativeThreadId tid; gpointer handle; - int thr_ret; handle = g_ptr_array_index (internal->owned_mutexes, 0); @@ -506,11 +499,11 @@ mono_w32mutex_abandon (void) if (!mono_w32handle_lookup (handle, type, (gpointer *)&mutex_handle)) { g_error ("%s: error looking up %s handle %p", - __func__, mono_w32handle_ops_typename (type), handle); + __func__, mono_w32handle_get_typename (type), handle); } mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: abandoning %s handle %p", - __func__, mono_w32handle_ops_typename (type), handle); + __func__, mono_w32handle_get_typename (type), handle); tid = MONO_UINT_TO_NATIVE_THREAD_ID (internal->tid); @@ -518,8 +511,7 @@ mono_w32mutex_abandon (void) g_error ("%s: trying to release mutex %p acquired by thread %p from thread %p", __func__, handle, (gpointer) mutex_handle->tid, (gpointer) tid); - thr_ret = mono_w32handle_lock_handle (handle); - g_assert (thr_ret == 0); + mono_w32handle_lock_handle (handle); mutex_handle->recursion = 0; mutex_handle->tid = 0; @@ -530,10 +522,9 @@ mono_w32mutex_abandon (void) thread_disown_mutex (internal, handle); mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: abandoned %s handle %p", - __func__, mono_w32handle_ops_typename (type), handle); + __func__, mono_w32handle_get_typename (type), handle); - thr_ret = mono_w32handle_unlock_handle (handle); - g_assert (thr_ret == 0); + mono_w32handle_unlock_handle (handle); } g_ptr_array_free (internal->owned_mutexes, TRUE);