From: Mathieu Desnoyers Date: Tue, 21 Feb 2012 02:32:25 +0000 (-0500) Subject: Compat layer for gettid X-Git-Tag: v2.1.0-rc1~97^2~30 X-Git-Url: http://git.liburcu.org/?p=lttng-ust.git;a=commitdiff_plain;h=49c0da7df5e7bd32c06d69822e9b92120bf4d392 Compat layer for gettid Signed-off-by: Mathieu Desnoyers --- 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