From 78bd0de1a91c751c6b495b97994ffbc39173ca27 Mon Sep 17 00:00:00 2001 From: Jeff Peeler Date: Sun, 12 Dec 2010 03:58:33 +0000 Subject: Add support for several platforms to obtain the real thread ID. Already had the pthread ID which is not the same. The most obvious enhancement is in the "core show threads" output. As stated in the utils header, if the platform isn't supported -1 is reported (instead of the process ID previously). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@298137 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/utils.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'main/utils.c') diff --git a/main/utils.c b/main/utils.c index 6f2c884d0..7ac62bd39 100644 --- a/main/utils.c +++ b/main/utils.c @@ -34,6 +34,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include #endif +#include +#if defined(__APPLE__) +#include +#elif defined(HAVE_SYS_THR_H) +#include +#endif + #include "asterisk/network.h" #define AST_API_MODULE /* ensure that inlinable API functions will be built in lock.h if required */ @@ -2081,3 +2088,21 @@ int _ast_asprintf(char **ret, const char *file, int lineno, const char *func, co return res; } #endif + +int ast_get_tid(void) +{ + int ret = -1; +#if defined (__linux) && defined(SYS_gettid) + ret = syscall(SYS_gettid); /* available since Linux 1.4.11 */ +#elif defined(__sun) + ret = pthread_self(); +#elif defined(__APPLE__) + ret = mach_thread_self(); + mach_port_deallocate(mach_task_self(), ret); +#elif defined(__FreeBSD__) && defined(HAVE_SYS_THR_H) + long lwpid; + thr_self(&lwpid); /* available since sys/thr.h creation 2003 */ + ret = lwpid; +#endif + return ret; +} -- cgit v1.2.3