Skip to content
Snippets Groups Projects
Commit 652cba4a authored by Martin Stjernholm's avatar Martin Stjernholm
Browse files

Made the logging functions atomic to work well in threaded tests.

parent 42f5b79f
Branches
Tags
No related merge requests found
...@@ -39,8 +39,32 @@ void log_start (int verbosity, int on_tty) ...@@ -39,8 +39,32 @@ void log_start (int verbosity, int on_tty)
last_line_inplace = 0; last_line_inplace = 0;
} }
protected Thread.Mutex log_mutex = Thread.Mutex();
protected int twiddler_counter = -1; 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) void log_msg (string msg, mixed... args)
//! Logs a testsuite message. The message is shown regardless of the //! Logs a testsuite message. The message is shown regardless of the
//! verbosity level. If the previous message was logged without a //! verbosity level. If the previous message was logged without a
...@@ -52,6 +76,8 @@ void log_msg (string msg, mixed... args) ...@@ -52,6 +76,8 @@ void log_msg (string msg, mixed... args)
{ {
if (sizeof (args)) msg = sprintf (msg, @args); if (sizeof (args)) msg = sprintf (msg, @args);
Thread.MutexKey lock = log_mutex->lock();
if (last_line_length) { if (last_line_length) {
write ("\n"); write ("\n");
last_line_length = 0; last_line_length = 0;
...@@ -63,7 +89,7 @@ void log_msg (string msg, mixed... args) ...@@ -63,7 +89,7 @@ void log_msg (string msg, mixed... args)
last_log = 0; last_log = 0;
} }
log_msg_cont (msg); unlocked_log_msg_cont (msg);
} }
void log_msg_cont (string msg, mixed... args) void log_msg_cont (string msg, mixed... args)
...@@ -73,26 +99,8 @@ void log_msg_cont (string msg, mixed... args) ...@@ -73,26 +99,8 @@ void log_msg_cont (string msg, mixed... args)
//! @[log_status]. //! @[log_status].
{ {
if (sizeof (args)) msg = sprintf (msg, @args); if (sizeof (args)) msg = sprintf (msg, @args);
Thread.MutexKey lock = log_mutex->lock();
if (last_line_inplace && last_line_length) { unlocked_log_msg_cont (msg);
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_status (string msg, mixed... args) void log_status (string msg, mixed... args)
...@@ -122,6 +130,8 @@ 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); if (sizeof (args)) msg = sprintf (msg, @args);
Thread.MutexKey lock = log_mutex->lock();
switch (verbosity) { switch (verbosity) {
case 0: case 0:
last_log = (msg != "" && msg); last_log = (msg != "" && msg);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment