summaryrefslogtreecommitdiff
path: root/main/utils.c
diff options
context:
space:
mode:
authorJeff Peeler <jpeeler@digium.com>2010-12-12 03:58:33 +0000
committerJeff Peeler <jpeeler@digium.com>2010-12-12 03:58:33 +0000
commit78bd0de1a91c751c6b495b97994ffbc39173ca27 (patch)
tree4f29a663898cf85e15ac911b9a1378b0ca5beccf /main/utils.c
parentcc541e6852338468565470fbd78a7e76115033a5 (diff)
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
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c25
1 files changed, 25 insertions, 0 deletions
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 <fcntl.h>
#endif
+#include <sys/syscall.h>
+#if defined(__APPLE__)
+#include <mach/mach.h>
+#elif defined(HAVE_SYS_THR_H)
+#include <sys/thr.h>
+#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;
+}