Reland "Remove criticalsection.cc dependency on platform_thread.cc."

This is a reland of 5af97ee3ad36cb6d386cfefa8c89d7c178015a07.

What's changed from the original?
- Moved the #include for <process.h> for Fuchsia to the types header.

Original change's description:
> Remove criticalsection.cc dependency on platform_thread.cc.
>
> As part of this, I'm moving global thread related functions over to
> platform_thread_types.* and introducing platform_thread_types.cc
> for the implementation.
>
> Change-Id: I4624877fb379e77d215f4ecd60f20b06d8df3ce5
> Bug: webrtc:8893
> Reviewed-on: https://webrtc-review.googlesource.com/53940
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Commit-Queue: Tommi <tommi@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#22037}

Bug: webrtc:8893
Change-Id: Idd0baa6756efd10ad11a5c6e4791eaa7a9dbc97f
Tbr: danilchap@webrtc.org
Reviewed-on: https://webrtc-review.googlesource.com/54800
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22068}
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 6dccc48..317c456 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -217,6 +217,7 @@
     "platform_file.h",
     "platform_thread.cc",
     "platform_thread.h",
+    "platform_thread_types.cc",
     "platform_thread_types.h",
     "ptr_util.h",
     "race_checker.cc",
diff --git a/rtc_base/criticalsection.cc b/rtc_base/criticalsection.cc
index d92b478..f9168d8 100644
--- a/rtc_base/criticalsection.cc
+++ b/rtc_base/criticalsection.cc
@@ -11,7 +11,7 @@
 #include "rtc_base/criticalsection.h"
 
 #include "rtc_base/checks.h"
-#include "rtc_base/platform_thread.h"
+#include "rtc_base/platform_thread_types.h"
 
 // TODO(tommi): Split this file up to per-platform implementation files.
 
diff --git a/rtc_base/platform_thread.cc b/rtc_base/platform_thread.cc
index 9495ef4..ca2ce13 100644
--- a/rtc_base/platform_thread.cc
+++ b/rtc_base/platform_thread.cc
@@ -20,71 +20,7 @@
 #include <sys/syscall.h>
 #endif
 
-#if defined(WEBRTC_FUCHSIA)
-#include <zircon/process.h>
-#endif
-
 namespace rtc {
-
-PlatformThreadId CurrentThreadId() {
-  PlatformThreadId ret;
-#if defined(WEBRTC_WIN)
-  ret = GetCurrentThreadId();
-#elif defined(WEBRTC_POSIX)
-#if defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
-  ret = pthread_mach_thread_np(pthread_self());
-#elif defined(WEBRTC_ANDROID)
-  ret = gettid();
-#elif defined(WEBRTC_FUCHSIA)
-  ret = zx_thread_self();
-#elif defined(WEBRTC_LINUX)
-  ret = syscall(__NR_gettid);
-#else
-  // Default implementation for nacl and solaris.
-  ret = reinterpret_cast<pid_t>(pthread_self());
-#endif
-#endif  // defined(WEBRTC_POSIX)
-  RTC_DCHECK(ret);
-  return ret;
-}
-
-PlatformThreadRef CurrentThreadRef() {
-#if defined(WEBRTC_WIN)
-  return GetCurrentThreadId();
-#elif defined(WEBRTC_POSIX)
-  return pthread_self();
-#endif
-}
-
-bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b) {
-#if defined(WEBRTC_WIN)
-  return a == b;
-#elif defined(WEBRTC_POSIX)
-  return pthread_equal(a, b);
-#endif
-}
-
-void SetCurrentThreadName(const char* name) {
-#if defined(WEBRTC_WIN)
-  struct {
-    DWORD dwType;
-    LPCSTR szName;
-    DWORD dwThreadID;
-    DWORD dwFlags;
-  } threadname_info = {0x1000, name, static_cast<DWORD>(-1), 0};
-
-  __try {
-    ::RaiseException(0x406D1388, 0, sizeof(threadname_info) / sizeof(DWORD),
-                     reinterpret_cast<ULONG_PTR*>(&threadname_info));
-  } __except (EXCEPTION_EXECUTE_HANDLER) {
-  }
-#elif defined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID)
-  prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(name));
-#elif defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
-  pthread_setname_np(name);
-#endif
-}
-
 namespace {
 #if defined(WEBRTC_WIN)
 void CALLBACK RaiseFlag(ULONG_PTR param) {
diff --git a/rtc_base/platform_thread.h b/rtc_base/platform_thread.h
index 25fa036..33921c2 100644
--- a/rtc_base/platform_thread.h
+++ b/rtc_base/platform_thread.h
@@ -20,15 +20,6 @@
 
 namespace rtc {
 
-PlatformThreadId CurrentThreadId();
-PlatformThreadRef CurrentThreadRef();
-
-// Compares two thread identifiers for equality.
-bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b);
-
-// Sets the current thread name.
-void SetCurrentThreadName(const char* name);
-
 // Callback function that the spawned thread will enter once spawned.
 // A return value of false is interpreted as that the function has no
 // more work to do and that the thread can be released.
diff --git a/rtc_base/platform_thread_types.cc b/rtc_base/platform_thread_types.cc
new file mode 100644
index 0000000..6426dae
--- /dev/null
+++ b/rtc_base/platform_thread_types.cc
@@ -0,0 +1,76 @@
+/*
+ *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/platform_thread_types.h"
+
+#if defined(WEBRTC_LINUX)
+#include <sys/prctl.h>
+#include <sys/syscall.h>
+#endif
+
+namespace rtc {
+
+PlatformThreadId CurrentThreadId() {
+#if defined(WEBRTC_WIN)
+  return GetCurrentThreadId();
+#elif defined(WEBRTC_POSIX)
+#if defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
+  return pthread_mach_thread_np(pthread_self());
+#elif defined(WEBRTC_ANDROID)
+  return gettid();
+#elif defined(WEBRTC_FUCHSIA)
+  return zx_thread_self();
+#elif defined(WEBRTC_LINUX)
+  return syscall(__NR_gettid);
+#else
+  // Default implementation for nacl and solaris.
+  return reinterpret_cast<pid_t>(pthread_self());
+#endif
+#endif  // defined(WEBRTC_POSIX)
+}
+
+PlatformThreadRef CurrentThreadRef() {
+#if defined(WEBRTC_WIN)
+  return GetCurrentThreadId();
+#elif defined(WEBRTC_POSIX)
+  return pthread_self();
+#endif
+}
+
+bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b) {
+#if defined(WEBRTC_WIN)
+  return a == b;
+#elif defined(WEBRTC_POSIX)
+  return pthread_equal(a, b);
+#endif
+}
+
+void SetCurrentThreadName(const char* name) {
+#if defined(WEBRTC_WIN)
+  struct {
+    DWORD dwType;
+    LPCSTR szName;
+    DWORD dwThreadID;
+    DWORD dwFlags;
+  } threadname_info = {0x1000, name, static_cast<DWORD>(-1), 0};
+
+  __try {
+    ::RaiseException(0x406D1388, 0, sizeof(threadname_info) / sizeof(DWORD),
+                     reinterpret_cast<ULONG_PTR*>(&threadname_info));
+  } __except (EXCEPTION_EXECUTE_HANDLER) {  // NOLINT
+  }
+#elif defined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID)
+  prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(name));  // NOLINT
+#elif defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
+  pthread_setname_np(name);
+#endif
+}
+
+}  // namespace rtc
diff --git a/rtc_base/platform_thread_types.h b/rtc_base/platform_thread_types.h
index 10c5de8..e6331e7 100644
--- a/rtc_base/platform_thread_types.h
+++ b/rtc_base/platform_thread_types.h
@@ -16,6 +16,7 @@
 #include <windows.h>
 #elif defined(WEBRTC_FUCHSIA)
 #include <zircon/types.h>
+#include <zircon/process.h>
 #elif defined(WEBRTC_POSIX)
 #include <pthread.h>
 #include <unistd.h>
@@ -32,6 +33,21 @@
 typedef pid_t PlatformThreadId;
 typedef pthread_t PlatformThreadRef;
 #endif
+
+// Retrieve the ID of the current thread.
+PlatformThreadId CurrentThreadId();
+
+// Retrieves a reference to the current thread. On Windows, this is the same
+// as CurrentThreadId. On other platforms it's the pthread_t returned by
+// pthread_self().
+PlatformThreadRef CurrentThreadRef();
+
+// Compares two thread identifiers for equality.
+bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b);
+
+// Sets the current thread name.
+void SetCurrentThreadName(const char* name);
+
 }  // namespace rtc
 
 #endif  // RTC_BASE_PLATFORM_THREAD_TYPES_H_