[PATCH v7 3/9] perf mutex: Add DEFINE_MUTEX() static initializer

From: Arnaldo Carvalho de Melo

Date: Thu Oct 01 2026 - 14:55:58 EST


From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

For file scope mutexes, so that they don't need a constructor function
to initialize them at startup, mirroring PTHREAD_MUTEX_INITIALIZER
while keeping the clang -Wthread-safety annotations of struct mutex.

Assisted-by: LLM
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/mutex.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/mutex.h b/tools/perf/util/mutex.h
index 70232d8d094f8bfc..b85a80ad60386aed 100644
--- a/tools/perf/util/mutex.h
+++ b/tools/perf/util/mutex.h
@@ -92,6 +92,9 @@ struct LOCKABLE mutex {
pthread_mutex_t lock;
};

+/* Statically initialized mutex, for the file scope ones. */
+#define DEFINE_MUTEX(name) struct mutex name = { .lock = PTHREAD_MUTEX_INITIALIZER }
+
/* A wrapper around the condition variable implementation. */
struct cond {
pthread_cond_t cond;
--
2.55.0