From ab396795fdedcdc02b8fee48bc95f6420a2a8346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 22 Feb 2024 12:46:18 +0100 Subject: [PATCH] Make 'tap' library counting multi-thread resilient --- test/tap/tap/tap.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/tap/tap/tap.cpp b/test/tap/tap/tap.cpp index 4369bddf60..8afb7939cd 100644 --- a/test/tap/tap/tap.cpp +++ b/test/tap/tap/tap.cpp @@ -87,7 +87,7 @@ vemit_tap(int pass, char const *fmt, va_list ap) { fprintf(tapout, "%sok %d%s", pass ? "" : "not ", - ++g_test.last, + __sync_add_and_fetch(&g_test.last, 1), (fmt && *fmt) ? " - " : ""); if (fmt && *fmt) vfprintf(tapout, fmt, ap); @@ -248,7 +248,7 @@ ok(int pass, char const *fmt, ...) va_start(ap, fmt); if (!pass && *g_test.todo == '\0') - ++g_test.failed; + __sync_add_and_fetch(&g_test.failed, 1); vemit_tap(pass, fmt, ap); va_end(ap); @@ -265,7 +265,7 @@ ok1(int const pass) memset(&ap, 0, sizeof(ap)); if (!pass && *g_test.todo == '\0') - ++g_test.failed; + __sync_add_and_fetch(&g_test.failed, 1); vemit_tap(pass, NULL, ap);