]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Convert Util_GetCurrentThreadId to VThreadBase_GetKernelID
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:50 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:50 +0000 (11:23 -0700)
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.

open-vm-tools/lib/include/util.h
open-vm-tools/lib/misc/util_misc.c
open-vm-tools/lib/misc/vthreadBase.c

index 48bacaa787c1ec5253ea63fad7c6d10a824fd380..df0735e919ac3468616d9fbdf668a12aeafb9dc5 100644 (file)
 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 <pthread.h>
-   typedef mach_port_t Util_ThreadID;
-#elif defined(__sun__)
-#  include <thread.h>
-   typedef thread_t Util_ThreadID;
-#elif defined(__FreeBSD__)
-#  include <pthread.h>
-   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,
index 81829a30fc9d7aafe33a616fd7c7f08a922845c0..b1d257d48921e85a104d360da79782991b1f8dfa 100644 (file)
@@ -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 <ctype.h>
 
 #if !defined(_WIN32)
-#  if defined(__linux__)
-#    include <sys/syscall.h> // for SYS_gettid
-#  endif
 #  include <unistd.h>
 #  include <pwd.h>
 #  include <sys/socket.h>    // for AF_INET[6]
 #  include <netinet/in.h>    // for INET6_ADDRSTRLEN
 #endif
 
-#if defined(__APPLE__) || defined(__FreeBSD__)
-#include <pthread.h>
-#elif defined(__sun__)
-#include <thread.h>
-#endif
-
 #if defined(__APPLE__)
 #include <CoreFoundation/CoreFoundation.h>
 #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 <unistd.h> 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
-}
-
-
 /*
  *-----------------------------------------------------------------------------
  *
index 37d2c3548857e394e40a7d76d2e688c662d1fda1..dd805ddea368c910753cf55d8483ef9c6d43bcf8 100644 (file)
@@ -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, ...)
  *