X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fio-layer%2Fsemaphores.c;h=a8131fa97f6a7d36d862f8a66f64cc5b8cb3c63b;hb=30490c764179561832248da804746e99fe252115;hp=8b4bb0ebcca6599b727ef5feb5d3b1f6791dd09f;hpb=9b3232e7df30dc895bf1d033196d106ae555c4a0;p=mono.git diff --git a/mono/io-layer/semaphores.c b/mono/io-layer/semaphores.c index 8b4bb0ebcca..a8131fa97f6 100644 --- a/mono/io-layer/semaphores.c +++ b/mono/io-layer/semaphores.c @@ -19,16 +19,11 @@ #include #include -#include #include -#include #include - -#if 0 -#define DEBUG(...) g_message(__VA_ARGS__) -#else -#define DEBUG(...) -#endif +#include +#include +#include static void sema_signal(gpointer handle); static gboolean sema_own (gpointer handle); @@ -88,11 +83,9 @@ static mono_once_t sem_ops_once=MONO_ONCE_INIT; static void sem_ops_init (void) { _wapi_handle_register_capabilities (WAPI_HANDLE_SEM, - WAPI_HANDLE_CAP_WAIT | - WAPI_HANDLE_CAP_SIGNAL); + (WapiHandleCapability)(WAPI_HANDLE_CAP_WAIT | WAPI_HANDLE_CAP_SIGNAL)); _wapi_handle_register_capabilities (WAPI_HANDLE_NAMEDSEM, - WAPI_HANDLE_CAP_WAIT | - WAPI_HANDLE_CAP_SIGNAL); + (WapiHandleCapability)(WAPI_HANDLE_CAP_WAIT | WAPI_HANDLE_CAP_SIGNAL)); } static void sema_signal(gpointer handle) @@ -113,11 +106,11 @@ static gboolean sema_own (gpointer handle) return(FALSE); } - DEBUG("%s: owning sem handle %p", __func__, handle); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: owning sem handle %p", __func__, handle); sem_handle->val--; - DEBUG ("%s: sem %p val now %d", __func__, handle, sem_handle->val); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: sem %p val now %d", __func__, handle, sem_handle->val); if(sem_handle->val==0) { _wapi_handle_set_signal_state (handle, FALSE, FALSE); @@ -137,7 +130,7 @@ static gboolean namedsema_own (gpointer handle) struct _WapiHandle_namedsem *namedsem_handle; gboolean ok; - DEBUG ("%s: owning named sem handle %p", __func__, handle); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: owning named sem handle %p", __func__, handle); ok = _wapi_lookup_handle (handle, WAPI_HANDLE_NAMEDSEM, (gpointer *)&namedsem_handle); @@ -149,7 +142,7 @@ static gboolean namedsema_own (gpointer handle) namedsem_handle->val--; - DEBUG ("%s: named sem %p val now %d", __func__, handle, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: named sem %p val now %d", __func__, handle, namedsem_handle->val); if (namedsem_handle->val == 0) { @@ -181,8 +174,6 @@ static gpointer sem_create (WapiSecurityAttributes *security G_GNUC_UNUSED, return(NULL); } - pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle, - handle); thr_ret = _wapi_handle_lock_handle (handle); g_assert (thr_ret == 0); @@ -190,12 +181,11 @@ static gpointer sem_create (WapiSecurityAttributes *security G_GNUC_UNUSED, _wapi_handle_set_signal_state (handle, TRUE, FALSE); } - DEBUG ("%s: Created semaphore handle %p initial %d max %d", + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Created semaphore handle %p initial %d max %d", __func__, handle, initial, max); thr_ret = _wapi_handle_unlock_handle (handle); g_assert (thr_ret == 0); - pthread_cleanup_pop (0); return(handle); } @@ -224,7 +214,7 @@ static gpointer namedsem_create (WapiSecurityAttributes *security G_GNUC_UNUSED, utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL); - DEBUG ("%s: Creating named sem [%s]", __func__, utf8_name); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Creating named sem [%s]", __func__, utf8_name); offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDSEM, utf8_name); @@ -288,7 +278,7 @@ static gpointer namedsem_create (WapiSecurityAttributes *security G_GNUC_UNUSED, _wapi_handle_unlock_shared_handles (); } - DEBUG ("%s: returning named sem handle %p", __func__, handle); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning named sem handle %p", __func__, handle); cleanup: g_free (utf8_name); @@ -322,14 +312,14 @@ gpointer CreateSemaphore(WapiSecurityAttributes *security G_GNUC_UNUSED, gint32 mono_once (&sem_ops_once, sem_ops_init); if (max <= 0) { - DEBUG ("%s: max <= 0", __func__); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: max <= 0", __func__); SetLastError (ERROR_INVALID_PARAMETER); return(NULL); } if (initial > max || initial < 0) { - DEBUG ("%s: initial>max or < 0", __func__); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: initial>max or < 0", __func__); SetLastError (ERROR_INVALID_PARAMETER); return(NULL); @@ -357,12 +347,10 @@ static gboolean sem_release (gpointer handle, gint32 count, gint32 *prevcount) 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: sem %p val %d count %d", __func__, handle, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: sem %p val %d count %d", __func__, handle, sem_handle->val, count); /* Do this before checking for count overflow, because overflowing max @@ -374,7 +362,7 @@ static gboolean sem_release (gpointer handle, gint32 count, gint32 *prevcount) /* No idea why max is signed, but thats the spec :-( */ if (sem_handle->val + count > (guint32)sem_handle->max) { - DEBUG ("%s: sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count); goto end; } @@ -384,12 +372,11 @@ static gboolean sem_release (gpointer handle, gint32 count, gint32 *prevcount) ret = TRUE; - DEBUG ("%s: sem %p val now %d", __func__, handle, sem_handle->val); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: sem %p val now %d", __func__, handle, sem_handle->val); end: thr_ret = _wapi_handle_unlock_handle (handle); g_assert (thr_ret == 0); - pthread_cleanup_pop (0); return(ret); } @@ -413,7 +400,7 @@ static gboolean namedsem_release (gpointer handle, gint32 count, thr_ret = _wapi_handle_lock_shared_handles (); g_assert (thr_ret == 0); - DEBUG("%s: named sem %p val %d count %d", __func__, handle, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: named sem %p val %d count %d", __func__, handle, sem_handle->val, count); /* Do this before checking for count overflow, because overflowing max @@ -425,7 +412,7 @@ static gboolean namedsem_release (gpointer handle, gint32 count, /* No idea why max is signed, but thats the spec :-( */ if (sem_handle->val + count > (guint32)sem_handle->max) { - DEBUG ("%s: named sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: named sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count); goto end; } @@ -435,7 +422,7 @@ static gboolean namedsem_release (gpointer handle, gint32 count, ret = TRUE; - DEBUG("%s: named sem %p val now %d", __func__, handle, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: named sem %p val now %d", __func__, handle, sem_handle->val); end: @@ -494,7 +481,7 @@ gpointer OpenSemaphore (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UN utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL); - DEBUG ("%s: Opening named sem [%s]", __func__, utf8_name); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Opening named sem [%s]", __func__, utf8_name); offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDSEM, utf8_name); @@ -523,7 +510,7 @@ gpointer OpenSemaphore (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UN } ret = handle; - DEBUG ("%s: returning named sem handle %p", __func__, handle); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning named sem handle %p", __func__, handle); cleanup: g_free (utf8_name);