From: Ludovic Henry Date: Mon, 2 Nov 2015 16:06:47 +0000 (+0000) Subject: [trace] Synchronize output X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=e161b61b3d19113f84d9beca58391e38bfe50f8e;p=mono.git [trace] Synchronize output --- diff --git a/mono/mini/trace.c b/mono/mini/trace.c index d6aba0d8e0e..3d843f3b46b 100644 --- a/mono/mini/trace.c +++ b/mono/mini/trace.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "trace.h" #if defined (PLATFORM_ANDROID) || (defined (TARGET_IOS) && defined (TARGET_IOS)) @@ -51,6 +52,8 @@ static MonoTraceSpec trace_spec; +static volatile gint32 output_lock = 0; + gboolean mono_trace_eval_exception (MonoClass *klass) { @@ -413,6 +416,9 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) if (!trace_spec.enabled) return; + while (output_lock != 0 || InterlockedCompareExchange (&output_lock, 1, 0) != 0) + mono_thread_info_yield (); + fname = mono_method_full_name (method, TRUE); indent (1); printf ("ENTER: %s(", fname); @@ -420,8 +426,8 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) if (!ebp) { printf (") ip: %p\n", RETURN_ADDRESS_N (1)); - return; - } + goto unlock; + } sig = mono_method_signature (method); @@ -435,7 +441,7 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) if (gsctx && gsctx->is_gsharedvt) { /* Needs a ctx to get precise method */ printf (") \n"); - return; + goto unlock; } } } @@ -565,6 +571,9 @@ mono_trace_enter_method (MonoMethod *method, char *ebp) printf (")\n"); fflush (stdout); + +unlock: + mono_atomic_store_release (&output_lock, 0); } void @@ -578,6 +587,9 @@ mono_trace_leave_method (MonoMethod *method, ...) if (!trace_spec.enabled) return; + while (output_lock != 0 || InterlockedCompareExchange (&output_lock, 1, 0) != 0) + mono_thread_info_yield (); + va_start(ap, method); fname = mono_method_full_name (method, TRUE); @@ -593,7 +605,7 @@ mono_trace_leave_method (MonoMethod *method, ...) if (gsctx && gsctx->is_gsharedvt) { /* Needs a ctx to get precise method */ printf (") \n"); - return; + goto unlock; } } } @@ -703,6 +715,9 @@ handle_enum: //printf (" ip: %p\n", RETURN_ADDRESS_N (1)); printf ("\n"); fflush (stdout); + +unlock: + mono_atomic_store_release (&output_lock, 0); } void