[Piglit] [PATCH 09/13] util: Add func piglit_gettid()

Chad Versace chad.versace at linux.intel.com
Wed Mar 26 10:40:25 PDT 2014


On Linux, piglit_gettid() wraps the gettid() syscall.
It returns 0 on unsupported systems.

This is useful for printing messages in multi-threaded tests.

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 tests/util/piglit-util.c | 17 +++++++++++++++++
 tests/util/piglit-util.h |  9 ++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 1d0f393..ca7d4cd 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -28,12 +28,19 @@
 #include <windows.h>
 #endif
 
+#ifdef __linux__
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+#endif
+
 #include <assert.h>
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <inttypes.h>
 
 #ifdef PIGLIT_HAS_POSIX_CLOCK_MONOTONIC
 #include <time.h>
@@ -663,3 +670,13 @@ piglit_run_selected_subtests(const struct piglit_subtest *all_subtests,
 
 	return result;
 }
+
+uint64_t
+piglit_gettid(void)
+{
+#ifdef __linux__
+	return syscall(SYS_gettid);
+#else
+	return 0;
+#endif
+}
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index a90f59f..0f25d67 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -250,7 +250,14 @@ piglit_parse_subtest_args(int *argc, char *argv[],
 			  const char ***out_selected_subtests,
 			  size_t *out_num_selected_subtests);
 
-
+/**
+ * \brief Return the thread id.
+ *
+ * On Linux, this functions wraps the gettid() syscall.
+ * On unsupported systems, this returns 0.
+ */
+uint64_t
+piglit_gettid(void);
 
 #ifdef __cplusplus
 } /* end extern "C" */
-- 
1.8.5.3



More information about the Piglit mailing list