From 9ab7db37d11dcec840475933a8721672f02bff79 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Wed, 15 Jan 2020 17:05:45 +0000 Subject: va/va_trace: implement gettid() for BSDs ../va/va_trace.c:291:28: error: use of undeclared identifier '__NR_gettid' pid_t thd_id = syscall(__NR_gettid); ^ ../va/va_trace.c:669:28: error: use of undeclared identifier '__NR_gettid' pid_t thd_id = syscall(__NR_gettid); ^ ../va/va_trace.c:708:28: error: use of undeclared identifier '__NR_gettid' pid_t thd_id = syscall(__NR_gettid); ^ ../va/va_trace.c:1234:28: error: use of undeclared identifier '__NR_gettid' pid_t thd_id = syscall(__NR_gettid); ^ --- va/va_trace.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'va/va_trace.c') diff --git a/va/va_trace.c b/va/va_trace.c index 65179c5..f9847d2 100644 --- a/va/va_trace.c +++ b/va/va_trace.c @@ -48,12 +48,41 @@ #include #include #include -#include #include #include #include #include +#if defined(__linux__) +#include +#elif defined(__DragonFly__) || defined(__FreeBSD__) +#include +#elif defined(__NetBSD__) +#include +#elif defined(__sun) +#include +#endif + +#if !defined(__BIONIC__) +static pid_t gettid() +{ +#if defined(__linux__) + return syscall(__NR_gettid); +#elif defined(__DragonFly__) || defined(__FreeBSD__) + return pthread_getthreadid_np(); +#elif defined(__NetBSD__) + return _lwp_self(); +#elif defined(__OpenBSD__) + return getthrid(); +#elif defined(__sun) + return thr_self(); +#else +#warning "Cannot get kernel thread identifier on this platform." + return (intptr_t)pthread_self(); +#endif +} +#endif + /* * Env. to debug some issue, e.g. the decode/encode issue in a video conference scenerio: * .LIBVA_TRACE=log_file: general VA parameters saved into log_file @@ -288,7 +317,7 @@ static void add_trace_config_info( { struct trace_config_info *pconfig_info; int idx = 0; - pid_t thd_id = syscall(__NR_gettid); + pid_t thd_id = gettid(); LOCK_RESOURCE(pva_trace); @@ -666,7 +695,7 @@ static struct trace_log_file *start_tracing2log_file( { struct trace_log_files_manager *plog_files_mgr = NULL; struct trace_log_file *plog_file = NULL; - pid_t thd_id = syscall(__NR_gettid); + pid_t thd_id = gettid(); int i = 0; LOCK_RESOURCE(pva_trace); @@ -705,7 +734,7 @@ static void refresh_log_file( struct trace_context *ptra_ctx) { struct trace_log_file *plog_file = NULL; - pid_t thd_id = syscall(__NR_gettid); + pid_t thd_id = gettid(); int i = 0; plog_file = ptra_ctx->plog_file; @@ -1231,7 +1260,7 @@ static void internal_TraceUpdateContext ( { struct trace_context *trace_ctx = NULL; int i = 0, delete = 1; - pid_t thd_id = syscall(__NR_gettid); + pid_t thd_id = gettid(); if(tra_ctx_idx >= MAX_TRACE_CTX_NUM) return; -- cgit v1.2.1