From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:50 +0000 (-0700) Subject: Convert Util_GetCurrentThreadId to VThreadBase_GetKernelID X-Git-Tag: stable-10.2.0~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad5c63faa35f3b3e8e6a035e76ba1c043ae8c756;p=thirdparty%2Fopen-vm-tools.git Convert Util_GetCurrentThreadId to VThreadBase_GetKernelID This code now "lives" in VThreadBase since it is thread-related. The two functions behave (very) similarly. Some locations should use VThreadIDs instead of KernelIDs. Convert them. Remove the util.h and lib/misc bits. --- diff --git a/open-vm-tools/lib/include/util.h b/open-vm-tools/lib/include/util.h index 48bacaa78..df0735e91 100644 --- a/open-vm-tools/lib/include/util.h +++ b/open-vm-tools/lib/include/util.h @@ -55,26 +55,6 @@ extern "C" { #endif -/* - * Define the Util_ThreadID type, and assorted standard bits. - */ -#if defined(_WIN32) - typedef DWORD Util_ThreadID; -#elif defined(__linux__) || defined(__ANDROID__) - typedef pid_t Util_ThreadID; -#elif defined(__APPLE__) -# include - typedef mach_port_t Util_ThreadID; -#elif defined(__sun__) -# include - typedef thread_t Util_ThreadID; -#elif defined(__FreeBSD__) -# include - typedef pthread_t Util_ThreadID; -#else -# error "Need typedef for Util_ThreadID" -#endif - uint32 CRC_Compute(const uint8 *buf, int len); uint32 Util_Checksum32(const uint32 *buf, int len); uint32 Util_Checksum(const uint8 *buf, int len); @@ -98,7 +78,6 @@ char *Util_CompatGetLowerCaseCanonicalPath(const char* path); int Util_BumpNoFds(uint32 *cur, uint32 *wanted); Bool Util_CanonicalPathsIdentical(const char *path1, const char *path2); Bool Util_IsAbsolutePath(const char *path); -Util_ThreadID Util_GetCurrentThreadId(void); char *Util_DeriveFileName(const char *source, const char *name, diff --git a/open-vm-tools/lib/misc/util_misc.c b/open-vm-tools/lib/misc/util_misc.c index 81829a30f..b1d257d48 100644 --- a/open-vm-tools/lib/misc/util_misc.c +++ b/open-vm-tools/lib/misc/util_misc.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2016 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2017 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -41,9 +41,6 @@ #include #if !defined(_WIN32) -# if defined(__linux__) -# include // for SYS_gettid -# endif # include # include # include // for AF_INET[6] @@ -51,12 +48,6 @@ # include // for INET6_ADDRSTRLEN #endif -#if defined(__APPLE__) || defined(__FreeBSD__) -#include -#elif defined(__sun__) -#include -#endif - #if defined(__APPLE__) #include #endif @@ -366,77 +357,6 @@ Util_IsAbsolutePath(const char *path) // IN: path to check } -/* - *----------------------------------------------------------------------------- - * - * Util_GetCurrentThreadId -- - * - * Retrieves a unique thread identification suitable to identify a thread - * to kill it or change its scheduling priority. - * - * The tid is NOT guaranteed to be correct across fork(). - * - * Results: - * Unique thread identification on success. - * ASSERTs on failure (should not happen). - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -Util_ThreadID -Util_GetCurrentThreadId(void) -{ -#if defined(__linux__) && !defined(__ANDROID__) - /* - * Linux does not declare gettid, but the raw syscall - * works fine. We must supply our own TLS caching. - */ - static __thread pid_t tid; - if (UNLIKELY(tid == 0)) { - tid = (pid_t)syscall(SYS_gettid); - ASSERT(tid != -1); // All kernels that support TLS also implement gettid - } - return tid; - -#elif defined(__ANDROID__) - /* - * Bionic supplies a gettid implementation in that - * natively uses TLS. - */ - return gettid(); -#elif defined(__sun__) - /* - * The old thr_ API returns an integer thread identifier. It is - * still available with Solaris pthreads. - */ - return thr_self(); -#elif defined(__APPLE__) - /* - * NB: do not use mach_thread_self here. mach_thread_self returns - * a reference and requires a matching mach_port_deallocate, which - * would take two syscalls instead of zero. - */ - return pthread_mach_thread_np(pthread_self()); -#elif defined(__FreeBSD__) - /* - * These OSes do not implement OS-native thread IDs. You probably - * didn't need one anyway, but guess that pthread_self works - * well enough. - */ - ASSERT_ON_COMPILE(sizeof(Util_ThreadID) >= sizeof(pthread_t)); - - return pthread_self(); -#elif defined(_WIN32) - return GetCurrentThreadId(); -#else -#error "Unknown platform" -#endif -} - - /* *----------------------------------------------------------------------------- * diff --git a/open-vm-tools/lib/misc/vthreadBase.c b/open-vm-tools/lib/misc/vthreadBase.c index 37d2c3548..dd805ddea 100644 --- a/open-vm-tools/lib/misc/vthreadBase.c +++ b/open-vm-tools/lib/misc/vthreadBase.c @@ -775,9 +775,6 @@ VThreadBase_CurID(void) * Obviously, specific mechanisms for obtaining native IDs are *highly* * non-portable, as indicated by the _np suffixes. * - * TODO: merge with Util_GetCurrentThreadId(), or delete that function - * because anybody using it probably hasn't read the above disclaimer. - * * Results: * Some sort of system ID (e.g. LWP, Task, ...) *