Implement thread-id.h wrapper
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 19 Jun 2013 14:30:58 +0000 (10:30 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 19 Jun 2013 14:30:58 +0000 (10:30 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/Makefile.am
tests/thread-id.h [new file with mode: 0644]

index bbaa18f47e275d4f8d731c366d2cc88c1749c735..aa36bf447d2a0bd84fd42b59cb91f43f1afb7d88 100644 (file)
@@ -22,7 +22,7 @@ noinst_PROGRAMS = test_urcu test_urcu_dynamic_link test_urcu_timing \
        test_urcu_lfs_rcu_dynlink \
        test_urcu_multiflavor test_urcu_multiflavor_dynlink \
        test_urcu_fork
        test_urcu_lfs_rcu_dynlink \
        test_urcu_multiflavor test_urcu_multiflavor_dynlink \
        test_urcu_fork
-noinst_HEADERS = rcutorture.h test_urcu_multiflavor.h cpuset.h
+noinst_HEADERS = rcutorture.h test_urcu_multiflavor.h cpuset.h thread-id.h
 
 if COMPAT_ARCH
 COMPAT=$(top_srcdir)/compat_arch_@ARCHTYPE@.c
 
 if COMPAT_ARCH
 COMPAT=$(top_srcdir)/compat_arch_@ARCHTYPE@.c
diff --git a/tests/thread-id.h b/tests/thread-id.h
new file mode 100644 (file)
index 0000000..9378edc
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef _TEST_THREAD_ID_H
+#define _TEST_THREAD_ID_H
+
+/*
+ * thread-id.h
+ *
+ * Userspace RCU library - thread ID
+ *
+ * Copyright 2013 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+ * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program
+ * for any purpose,  provided the above notices are retained on all copies.
+ * Permission to modify the code and to distribute modified code is granted,
+ * provided the above notices are retained, and a notice that the code was
+ * modified is included with the above copyright notice.
+ */
+
+#ifdef __linux__
+# include <syscall.h>
+
+# if defined(_syscall0)
+_syscall0(pid_t, gettid)
+# elif defined(__NR_gettid)
+static inline pid_t gettid(void)
+{
+       return syscall(__NR_gettid);
+}
+# endif
+
+static inline
+unsigned long urcu_get_thread_id(void)
+{
+       return (unsigned long) gettid();
+}
+#elif defined(__FreeBSD__)
+# include <pthread_np.h>
+
+static inline
+unsigned long urcu_get_thread_id(void)
+{
+       return (unsigned long) pthread_getthreadid_np();
+}
+#else
+# warning "use pid as thread ID"
+static inline
+unsigned long urcu_get_thread_id(void)
+{
+       return (unsigned long) getpid();
+}
+#endif
+
+#endif /* _TEST_THREAD_ID_H */
This page took 0.026662 seconds and 4 git commands to generate.