Replace DEBUG messages with calls to mono_trace
[mono.git] / mono / io-layer / wait.c
index 2d94e91d4fdf7955bfe7d7cd9e164ba5552a02fa..82a441ee3b8c71a792c3186fb6111db4be7f8a7a 100644 (file)
 #include <mono/io-layer/wapi.h>
 #include <mono/io-layer/handles-private.h>
 #include <mono/io-layer/wapi-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-logger-internals.h>
 
 static gboolean own_if_signalled(gpointer handle)
 {
@@ -113,7 +109,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        
        if (_wapi_handle_test_capabilities (handle,
                                            WAPI_HANDLE_CAP_WAIT) == FALSE) {
-               DEBUG ("%s: handle %p can't be waited for", __func__,
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p can't be waited for", __func__,
                           handle);
 
                return(WAIT_FAILED);
@@ -122,7 +118,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        _wapi_handle_ops_prewait (handle);
        
        if (_wapi_handle_test_capabilities (handle, WAPI_HANDLE_CAP_SPECIAL_WAIT) == TRUE) {
-               DEBUG ("%s: handle %p has special wait", __func__, handle);
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p has special wait", __func__, handle);
 
                ret = _wapi_handle_ops_special_wait (handle, timeout, alertable);
        
@@ -133,7 +129,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        }
        
        
-       DEBUG ("%s: locking handle %p", __func__, handle);
+       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: locking handle %p", __func__, handle);
 
        thr_ret = _wapi_handle_lock_handle (handle);
        g_assert (thr_ret == 0);
@@ -141,7 +137,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        if (_wapi_handle_test_capabilities (handle,
                                            WAPI_HANDLE_CAP_OWN) == TRUE) {
                if (own_if_owned (handle) == TRUE) {
-                       DEBUG ("%s: handle %p already owned", __func__,
+                       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p already owned", __func__,
                                   handle);
                        ret = WAIT_OBJECT_0;
                        goto done;
@@ -149,7 +145,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        }
 
        if (own_if_signalled (handle) == TRUE) {
-               DEBUG ("%s: handle %p already signalled", __func__,
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p already signalled", __func__,
                           handle);
 
                ret=WAIT_OBJECT_0;
@@ -167,7 +163,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
                _wapi_handle_ops_prewait (handle);
 
                if (own_if_signalled (handle)) {
-                       DEBUG ("%s: handle %p signalled", __func__,
+                       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p signalled", __func__,
                                   handle);
 
                        ret = WAIT_OBJECT_0;
@@ -182,7 +178,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
                         * if someone else got in before us.)
                         */
                        if (own_if_signalled (handle)) {
-                               DEBUG ("%s: handle %p signalled", __func__,
+                               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p signalled", __func__,
                                           handle);
 
                                ret=WAIT_OBJECT_0;
@@ -194,14 +190,14 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        } while(waited == 0 && !apc_pending);
 
        /* Timeout or other error */
-       DEBUG ("%s: wait on handle %p error: %s", __func__, handle,
+       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: wait on handle %p error: %s", __func__, handle,
                   strerror (waited));
 
        ret = apc_pending ? WAIT_IO_COMPLETION : WAIT_TIMEOUT;
 
 done:
 
-       DEBUG ("%s: unlocking handle %p", __func__, handle);
+       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unlocking handle %p", __func__, handle);
        
        thr_ret = _wapi_handle_unlock_handle (handle);
        g_assert (thr_ret == 0);
@@ -253,7 +249,7 @@ guint32 WaitForSingleObject(gpointer handle, guint32 timeout)
 guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
                            guint32 timeout, gboolean alertable)
 {
-       guint32 ret, waited;
+       guint32 ret = 0, waited;
        int thr_ret;
        gboolean apc_pending = FALSE;
        gpointer current_thread = wapi_get_current_thread_handle ();
@@ -308,7 +304,7 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
                return (WAIT_FAILED);
        }
 
-       DEBUG ("%s: locking handle %p", __func__, wait);
+       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: locking handle %p", __func__, wait);
 
        thr_ret = _wapi_handle_lock_handle (wait);
        g_assert (thr_ret == 0);
@@ -317,7 +313,7 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
 
        if (_wapi_handle_test_capabilities (wait, WAPI_HANDLE_CAP_OWN)==TRUE) {
                if (own_if_owned (wait)) {
-                       DEBUG ("%s: handle %p already owned", __func__,
+                       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p already owned", __func__,
                                   wait);
                        ret = WAIT_OBJECT_0;
                        goto done;
@@ -325,7 +321,7 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
        }
 
        if (own_if_signalled (wait)) {
-               DEBUG ("%s: handle %p already signalled", __func__, wait);
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p already signalled", __func__, wait);
 
                ret = WAIT_OBJECT_0;
                goto done;
@@ -337,7 +333,7 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
                _wapi_handle_ops_prewait (wait);
        
                if (own_if_signalled (wait)) {
-                       DEBUG ("%s: handle %p signalled", __func__, wait);
+                       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p signalled", __func__, wait);
 
                        ret = WAIT_OBJECT_0;
                        goto done;
@@ -351,7 +347,7 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
                         * if someone else got in before us.)
                         */
                        if (own_if_signalled (wait)) {
-                               DEBUG ("%s: handle %p signalled", __func__,
+                               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p signalled", __func__,
                                           wait);
 
                                ret = WAIT_OBJECT_0;
@@ -363,14 +359,13 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
        } while(waited == 0 && !apc_pending);
 
        /* Timeout or other error */
-       DEBUG ("%s: wait on handle %p error: %s", __func__, wait,
-                  strerror (ret));
+       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: wait on handle %p error: %s", __func__, wait, strerror (ret));
 
        ret = apc_pending ? WAIT_IO_COMPLETION : WAIT_TIMEOUT;
 
 done:
 
-       DEBUG ("%s: unlocking handle %p", __func__, wait);
+       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unlocking handle %p", __func__, wait);
 
        thr_ret = _wapi_handle_unlock_handle (wait);
        g_assert (thr_ret == 0);
@@ -385,7 +380,7 @@ static gboolean test_and_own (guint32 numobjects, gpointer *handles,
        gboolean done;
        int i;
        
-       DEBUG ("%s: locking handles", __func__);
+       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: locking handles", __func__);
        
        done = _wapi_handle_count_signalled_handles (numobjects, handles,
                                                     waitall, count, lowest);
@@ -399,7 +394,7 @@ static gboolean test_and_own (guint32 numobjects, gpointer *handles,
                }
        }
        
-       DEBUG ("%s: unlocking handles", __func__);
+       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unlocking handles", __func__);
 
        _wapi_handle_unlock_handles (numobjects, handles);
 
@@ -457,7 +452,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
        }
        
        if (numobjects > MAXIMUM_WAIT_OBJECTS) {
-               DEBUG ("%s: Too many handles: %d", __func__, numobjects);
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Too many handles: %d", __func__, numobjects);
 
                return(WAIT_FAILED);
        }
@@ -472,7 +467,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                        handles[i] = wapi_get_current_thread_handle ();
                        
                        if (handles[i] == NULL) {
-                               DEBUG ("%s: Handle %d bogus", __func__, i);
+                               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Handle %d bogus", __func__, i);
 
                                bogustype = TRUE;
                                break;
@@ -480,7 +475,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                }
 
                if ((GPOINTER_TO_UINT (handles[i]) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
-                       DEBUG ("%s: Handle %d pseudo process", __func__,
+                       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Handle %d pseudo process", __func__,
                                   i);
 
                        bogustype = TRUE;
@@ -488,7 +483,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                }
 
                if (_wapi_handle_test_capabilities (handles[i], WAPI_HANDLE_CAP_WAIT) == FALSE) {
-                       DEBUG ("%s: Handle %p can't be waited for",
+                       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Handle %p can't be waited for",
                                   __func__, handles[i]);
 
                        bogustype = TRUE;
@@ -508,13 +503,13 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
        }
 
        if (duplicate == TRUE) {
-               DEBUG ("%s: Returning due to duplicates", __func__);
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Returning due to duplicates", __func__);
 
                return(WAIT_FAILED);
        }
 
        if (bogustype == TRUE) {
-               DEBUG ("%s: Returning due to bogus type", __func__);
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Returning due to bogus type", __func__);
 
                return(WAIT_FAILED);
        }
@@ -556,7 +551,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                        }
                }
                
-               DEBUG ("%s: locking signal mutex", __func__);
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: locking signal mutex", __func__);
 
                thr_ret = _wapi_handle_lock_signal_mutex ();
                g_assert (thr_ret == 0);
@@ -582,7 +577,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                        ret = 0;
                }
 
-               DEBUG ("%s: unlocking signal mutex", __func__);
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unlocking signal mutex", __func__);
 
                thr_ret = _wapi_handle_unlock_signal_mutex (NULL);
                g_assert (thr_ret == 0);
@@ -605,7 +600,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                        /* Didn't get all handles, and there was a
                         * timeout or other error
                         */
-                       DEBUG ("%s: wait returned error: %s", __func__,
+                       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: wait returned error: %s", __func__,
                                   strerror (ret));
 
                        if(ret==ETIMEDOUT) {