#include <mono/io-layer/wapi.h>
#include <mono/io-layer/wapi-private.h>
-#include <mono/io-layer/misc-private.h>
#include <mono/io-layer/handles-private.h>
-#include <mono/io-layer/mono-mutex.h>
#include <mono/io-layer/mutex-private.h>
-
-#if 0
-#define DEBUG(...) g_message(__VA_ARGS__)
-#else
-#define DEBUG(...)
-#endif
+#include <mono/io-layer/io-trace.h>
+#include <mono/utils/mono-once.h>
+#include <mono/utils/mono-logger-internals.h>
static void mutex_signal(gpointer handle);
static gboolean mutex_own (gpointer handle);
static void mutex_ops_init (void)
{
_wapi_handle_register_capabilities (WAPI_HANDLE_MUTEX,
- WAPI_HANDLE_CAP_WAIT |
- WAPI_HANDLE_CAP_SIGNAL |
- WAPI_HANDLE_CAP_OWN);
+ (WapiHandleCapability)(WAPI_HANDLE_CAP_WAIT | WAPI_HANDLE_CAP_SIGNAL | WAPI_HANDLE_CAP_OWN));
_wapi_handle_register_capabilities (WAPI_HANDLE_NAMEDMUTEX,
- WAPI_HANDLE_CAP_WAIT |
- WAPI_HANDLE_CAP_SIGNAL |
- WAPI_HANDLE_CAP_OWN);
+ (WapiHandleCapability)(WAPI_HANDLE_CAP_WAIT | WAPI_HANDLE_CAP_SIGNAL | WAPI_HANDLE_CAP_OWN));
}
static void mutex_signal(gpointer handle)
_wapi_thread_own_mutex (handle);
- DEBUG("%s: owning mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: owning mutex handle %p", __func__, handle);
_wapi_handle_set_signal_state (handle, FALSE, FALSE);
mutex_handle->tid = pthread_self ();
mutex_handle->recursion++;
- DEBUG ("%s: mutex handle %p locked %d times by %d:%ld", __func__,
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: mutex handle %p locked %d times by %d:%ld", __func__,
handle, mutex_handle->recursion, mutex_handle->pid,
mutex_handle->tid);
return(FALSE);
}
- DEBUG("%s: testing ownership mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: testing ownership mutex handle %p", __func__, handle);
if (mutex_handle->recursion > 0 &&
mutex_handle->pid == _wapi_getpid () &&
pthread_equal (mutex_handle->tid, pthread_self ())) {
- DEBUG ("%s: mutex handle %p owned by %d:%ld", __func__,
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: mutex handle %p owned by %d:%ld", __func__,
handle, _wapi_getpid (), pthread_self ());
return(TRUE);
} else {
- DEBUG ("%s: mutex handle %p not owned by %d:%ld, but locked %d times by %d:%ld", __func__, handle, _wapi_getpid (), pthread_self (), mutex_handle->recursion, mutex_handle->pid, mutex_handle->tid);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: mutex handle %p not owned by %d:%ld, but locked %d times by %d:%ld", __func__, handle, _wapi_getpid (), pthread_self (), mutex_handle->recursion, mutex_handle->pid, mutex_handle->tid);
return(FALSE);
}
struct _WapiHandle_namedmutex *namedmutex_handle;
gboolean ok;
- DEBUG ("%s: owning named mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: owning named mutex handle %p", __func__, handle);
ok = _wapi_lookup_handle (handle, WAPI_HANDLE_NAMEDMUTEX,
(gpointer *)&namedmutex_handle);
_wapi_shared_handle_set_signal_state (handle, FALSE);
- DEBUG ("%s: mutex handle %p locked %d times by %d:%ld", __func__,
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: mutex handle %p locked %d times by %d:%ld", __func__,
handle, namedmutex_handle->recursion,
namedmutex_handle->pid, namedmutex_handle->tid);
return(FALSE);
}
- DEBUG ("%s: testing ownership mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: testing ownership mutex handle %p", __func__, handle);
if (namedmutex_handle->recursion > 0 &&
namedmutex_handle->pid == _wapi_getpid () &&
pthread_equal (namedmutex_handle->tid, pthread_self ())) {
- DEBUG ("%s: mutex handle %p owned by %d:%ld", __func__,
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: mutex handle %p owned by %d:%ld", __func__,
handle, _wapi_getpid (), pthread_self ());
return(TRUE);
} else {
- DEBUG ("%s: mutex handle %p not owned by %d:%ld, but locked %d times by %d:%ld", __func__, handle, _wapi_getpid (), pthread_self (), namedmutex_handle->recursion, namedmutex_handle->pid, namedmutex_handle->tid);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: mutex handle %p not owned by %d:%ld, but locked %d times by %d:%ld", __func__, handle, _wapi_getpid (), pthread_self (), namedmutex_handle->recursion, namedmutex_handle->pid, namedmutex_handle->tid);
return(FALSE);
}
return;
}
- DEBUG ("%s: Checking ownership of named mutex handle %p", __func__,
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Checking ownership of named mutex handle %p", __func__,
handle);
if (namedmutex_handle->recursion == 0) {
- DEBUG ("%s: Named mutex handle %p not owned", __func__,
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Named mutex handle %p not owned", __func__,
handle);
} else if (namedmutex_handle->pid == _wapi_getpid ()) {
- DEBUG ("%s: Named mutex handle %p owned by this process",
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Named mutex handle %p owned by this process",
__func__, handle);
} else {
int thr_ret;
gpointer proc_handle;
- DEBUG ("%s: Named mutex handle %p owned by another process", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Named mutex handle %p owned by another process", __func__, handle);
proc_handle = OpenProcess (0, 0, namedmutex_handle->pid);
if (proc_handle == NULL) {
/* Didn't find the process that this handle
* was owned by, overriding it
*/
- DEBUG ("%s: overriding old owner of named mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: overriding old owner of named mutex handle %p", __func__, handle);
thr_ret = _wapi_handle_lock_shared_handles ();
g_assert (thr_ret == 0);
_wapi_shared_handle_set_signal_state (handle, TRUE);
_wapi_handle_unlock_shared_handles ();
} else {
- DEBUG ("%s: Found active pid %d for named mutex handle %p", __func__, namedmutex_handle->pid, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Found active pid %d for named mutex handle %p", __func__, namedmutex_handle->pid, handle);
}
if (proc_handle != NULL)
CloseProcess (proc_handle);
return;
}
- pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
- handle);
thr_ret = _wapi_handle_lock_handle (handle);
g_assert (thr_ret == 0);
if (mutex_handle->pid == pid &&
pthread_equal (mutex_handle->tid, tid)) {
- DEBUG ("%s: Mutex handle %p abandoned!", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Mutex handle %p abandoned!", __func__, handle);
mutex_handle->recursion = 0;
mutex_handle->pid = 0;
thr_ret = _wapi_handle_unlock_handle (handle);
g_assert (thr_ret == 0);
- pthread_cleanup_pop (0);
}
static void namedmutex_abandon (gpointer handle, pid_t pid, pthread_t tid)
if (mutex_handle->pid == pid &&
pthread_equal (mutex_handle->tid, tid)) {
- DEBUG ("%s: Mutex handle %p abandoned!", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Mutex handle %p abandoned!", __func__, handle);
mutex_handle->recursion = 0;
mutex_handle->pid = 0;
*/
SetLastError (ERROR_SUCCESS);
- DEBUG ("%s: Creating unnamed mutex", __func__);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Creating unnamed mutex", __func__);
handle = _wapi_handle_new (WAPI_HANDLE_MUTEX, &mutex_handle);
if (handle == _WAPI_HANDLE_INVALID) {
return(NULL);
}
- pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
- handle);
thr_ret = _wapi_handle_lock_handle (handle);
g_assert (thr_ret == 0);
_wapi_handle_set_signal_state (handle, TRUE, FALSE);
}
- DEBUG ("%s: returning mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning mutex handle %p", __func__, handle);
thr_ret = _wapi_handle_unlock_handle (handle);
g_assert (thr_ret == 0);
- pthread_cleanup_pop (0);
return(handle);
}
utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
- DEBUG ("%s: Creating named mutex [%s]", __func__, utf8_name);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Creating named mutex [%s]", __func__, utf8_name);
offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDMUTEX,
utf8_name);
_wapi_handle_unlock_shared_handles ();
}
- DEBUG ("%s: returning mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning mutex handle %p", __func__, handle);
cleanup:
g_free (utf8_name);
return(FALSE);
}
- pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
- handle);
thr_ret = _wapi_handle_lock_handle (handle);
g_assert (thr_ret == 0);
- DEBUG("%s: Releasing mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Releasing mutex handle %p", __func__, handle);
if (!pthread_equal (mutex_handle->tid, tid) ||
mutex_handle->pid != pid) {
- DEBUG("%s: We don't own mutex handle %p (owned by %d:%ld, me %d:%ld)", __func__, handle, mutex_handle->pid, mutex_handle->tid, _wapi_getpid (), tid);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: We don't own mutex handle %p (owned by %d:%ld, me %d:%ld)", __func__, handle, mutex_handle->pid, mutex_handle->tid, _wapi_getpid (), tid);
goto cleanup;
}
if(mutex_handle->recursion==0) {
_wapi_thread_disown_mutex (handle);
- DEBUG("%s: Unlocking mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Unlocking mutex handle %p", __func__, handle);
mutex_handle->pid=0;
mutex_handle->tid=0;
cleanup:
thr_ret = _wapi_handle_unlock_handle (handle);
g_assert (thr_ret == 0);
- pthread_cleanup_pop (0);
return(ret);
}
thr_ret = _wapi_handle_lock_shared_handles ();
g_assert (thr_ret == 0);
- DEBUG("%s: Releasing mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Releasing mutex handle %p", __func__, handle);
if (!pthread_equal (mutex_handle->tid, tid) ||
mutex_handle->pid != pid) {
- DEBUG("%s: We don't own mutex handle %p (owned by %d:%ld, me %d:%ld)", __func__, handle, mutex_handle->pid, mutex_handle->tid, _wapi_getpid (), tid);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: We don't own mutex handle %p (owned by %d:%ld, me %d:%ld)", __func__, handle, mutex_handle->pid, mutex_handle->tid, _wapi_getpid (), tid);
goto cleanup;
}
if(mutex_handle->recursion==0) {
_wapi_thread_disown_mutex (handle);
- DEBUG("%s: Unlocking mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Unlocking mutex handle %p", __func__, handle);
mutex_handle->pid=0;
mutex_handle->tid=0;
utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
- DEBUG ("%s: Opening named mutex [%s]", __func__, utf8_name);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Opening named mutex [%s]", __func__, utf8_name);
offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDMUTEX,
utf8_name);
}
ret = handle;
- DEBUG ("%s: returning named mutex handle %p", __func__, handle);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning named mutex handle %p", __func__, handle);
cleanup:
g_free (utf8_name);