Add common util to set thread name
[lttng-tools.git] / src / common / compat / pthread.h
diff --git a/src/common/compat/pthread.h b/src/common/compat/pthread.h
new file mode 100644 (file)
index 0000000..a5f91b3
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ */
+
+#ifndef _COMPAT_PTHREAD_H
+#define _COMPAT_PTHREAD_H
+
+#include <pthread.h>
+
+#if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID)
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+       return pthread_setname_np(pthread_self(), name);
+}
+#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+       return pthread_setname_np(name);
+}
+#else
+/*
+ * For platforms without thread name support, do nothing.
+ */
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+       return -ENOSYS;
+}
+#endif
+
+#endif /* _COMPAT_PTHREAD_H */
This page took 0.024344 seconds and 5 git commands to generate.