mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-21 04:46:29 +00:00
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
This commit is contained in:
25
main/utils.c
25
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user