From 36e2ba2a19ec6698ed8dfb8c9bde683368334372 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 20 Feb 2012 21:32:25 -0500 Subject: [PATCH] Compat layer for gettid Signed-off-by: Mathieu Desnoyers --- include/Makefile.am | 1 + include/lttng/ust-tid.h | 44 +++++++++++++++++++++++++++++++ include/usterr-signal-safe.h | 4 +-- include/usterr.h | 3 ++- liblttng-ust/lttng-context-vtid.c | 20 +------------- 5 files changed, 50 insertions(+), 22 deletions(-) create mode 100644 include/lttng/ust-tid.h diff --git a/include/Makefile.am b/include/Makefile.am index 66b9ab0a..571e32f9 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -25,6 +25,7 @@ noinst_HEADERS = \ usterr-signal-safe.h \ ust_snprintf.h \ ust-comm.h \ + lttng/ust-tid.h \ lttng/bitfield.h \ helper.h \ share.h diff --git a/include/lttng/ust-tid.h b/include/lttng/ust-tid.h new file mode 100644 index 00000000..c6819f25 --- /dev/null +++ b/include/lttng/ust-tid.h @@ -0,0 +1,44 @@ +#ifndef _LTTNG_UST_TID_H +#define _LTTNG_UST_TID_H + +/* + * lttng/ust-tid.h + * + * Copyright 2012 (c) - Mathieu Desnoyers + * + * gettid compatibility layer. + * + * 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 +#endif + +#if defined(_syscall0) +_syscall0(pid_t, gettid) +#elif defined(__NR_gettid) +#include +static inline pid_t gettid(void) +{ + return syscall(__NR_gettid); +} +#else +#include +#include + +#warning "use pid as tid" +static inline pid_t gettid(void) +{ + return getpid(); +} +#endif + +#endif /* _LTTNG_UST_TID_H */ diff --git a/include/usterr-signal-safe.h b/include/usterr-signal-safe.h index 375eff7c..d46b0f6a 100644 --- a/include/usterr-signal-safe.h +++ b/include/usterr-signal-safe.h @@ -26,8 +26,8 @@ #include #include #include - #include +#include "lttng/ust-tid.h" enum ust_loglevel { UST_LOGLEVEL_UNKNOWN = 0, @@ -85,7 +85,7 @@ do { \ do { \ sigsafe_print_err(UST_STR_COMPONENT "[%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" UST_XSTR(__LINE__) ")\n", \ (long) getpid(), \ - (long) syscall(SYS_gettid), \ + (long) gettid(), \ ## args, __func__); \ fflush(stderr); \ } while(0) diff --git a/include/usterr.h b/include/usterr.h index 35d576ec..86c9bf86 100644 --- a/include/usterr.h +++ b/include/usterr.h @@ -27,6 +27,7 @@ #include #include +#include "lttng/ust-tid.h" #include "share.h" enum ust_loglevel { @@ -57,7 +58,7 @@ static inline int ust_debug(void) do { \ fprintf(stderr, UST_STR_COMPONENT "[%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" XSTR(__LINE__) ")\n", \ (long) getpid(), \ - (long) syscall(SYS_gettid), \ + (long) gettid(), \ ## args, \ __func__); \ } while(0) diff --git a/liblttng-ust/lttng-context-vtid.c b/liblttng-ust/lttng-context-vtid.c index 6f7e078d..3fe86405 100644 --- a/liblttng-ust/lttng-context-vtid.c +++ b/liblttng-ust/lttng-context-vtid.c @@ -12,25 +12,7 @@ #include #include #include - -#ifdef __linux__ -#include -#endif - -#if defined(_syscall0) -_syscall0(pid_t, gettid) -#elif defined(__NR_gettid) -static inline pid_t gettid(void) -{ - return syscall(__NR_gettid); -} -#else -#warning "use pid as tid" -static inline pid_t gettid(void) -{ - return getpid(); -} -#endif +#include /* * We cache the result to ensure we don't trigger a system call for -- 2.34.1