diff --git a/lib/modules/Tools.pmod/Testsuite.pmod b/lib/modules/Tools.pmod/Testsuite.pmod index 6eddb62814b343510fc9ca5ec4725b439e5ef6e7..650e28c131be4927e2a12c92fe71807c65ce6d18 100644 --- a/lib/modules/Tools.pmod/Testsuite.pmod +++ b/lib/modules/Tools.pmod/Testsuite.pmod @@ -39,8 +39,32 @@ void log_start (int verbosity, int on_tty) last_line_inplace = 0; } +protected Thread.Mutex log_mutex = Thread.Mutex(); protected int twiddler_counter = -1; +protected void unlocked_log_msg_cont (string msg) +{ + if (last_line_inplace && last_line_length) { + write ("\n"); + last_line_length = 0; + } + + last_log = 0; + write (msg); + twiddler_counter = -1; + last_line_inplace = 0; + + if (has_suffix (msg, "\n") || has_suffix (msg, "\r")) + last_line_length = 0; + else { + array(string) msg_lines = msg / "\n"; + if (sizeof (msg_lines) > 1) last_line_length = 0; + // FIXME: This length calculation is too simplistic since it + // assumes 1 char == 1 position. + last_line_length += sizeof (msg_lines[-1]); + } +} + void log_msg (string msg, mixed... args) //! Logs a testsuite message. The message is shown regardless of the //! verbosity level. If the previous message was logged without a @@ -52,6 +76,8 @@ void log_msg (string msg, mixed... args) { if (sizeof (args)) msg = sprintf (msg, @args); + Thread.MutexKey lock = log_mutex->lock(); + if (last_line_length) { write ("\n"); last_line_length = 0; @@ -63,7 +89,7 @@ void log_msg (string msg, mixed... args) last_log = 0; } - log_msg_cont (msg); + unlocked_log_msg_cont (msg); } void log_msg_cont (string msg, mixed... args) @@ -73,26 +99,8 @@ void log_msg_cont (string msg, mixed... args) //! @[log_status]. { if (sizeof (args)) msg = sprintf (msg, @args); - - if (last_line_inplace && last_line_length) { - write ("\n"); - last_line_length = 0; - } - - last_log = 0; - write (msg); - twiddler_counter = -1; - last_line_inplace = 0; - - if (has_suffix (msg, "\n") || has_suffix (msg, "\r")) - last_line_length = 0; - else { - array(string) msg_lines = msg / "\n"; - if (sizeof (msg_lines) > 1) last_line_length = 0; - // FIXME: This length calculation is too simplistic since it - // assumes 1 char == 1 position. - last_line_length += sizeof (msg_lines[-1]); - } + Thread.MutexKey lock = log_mutex->lock(); + unlocked_log_msg_cont (msg); } void log_status (string msg, mixed... args) @@ -122,6 +130,8 @@ void log_status (string msg, mixed... args) { if (sizeof (args)) msg = sprintf (msg, @args); + Thread.MutexKey lock = log_mutex->lock(); + switch (verbosity) { case 0: last_log = (msg != "" && msg);