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}
This commit is contained in:
Tommi
2018-02-17 11:46:14 +01:00
committed by Commit Bot
parent 80dd7b5d68
commit 1f3f3c2d19
6 changed files with 94 additions and 74 deletions

View File

@ -217,6 +217,7 @@ rtc_source_set("rtc_base_approved_generic") {
"platform_file.h",
"platform_thread.cc",
"platform_thread.h",
"platform_thread_types.cc",
"platform_thread_types.h",
"ptr_util.h",
"race_checker.cc",

View File

@ -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.

View File

@ -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) {

View File

@ -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.

View File

@ -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

View File

@ -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 pthread_t PlatformThreadRef;
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_