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}
This commit is contained in:
@ -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",
|
||||
|
@ -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.
|
||||
|
||||
|
@ -25,66 +25,6 @@
|
||||
#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) {
|
||||
|
@ -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.
|
||||
|
80
rtc_base/platform_thread_types.cc
Normal file
80
rtc_base/platform_thread_types.cc
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#if defined(WEBRTC_FUCHSIA)
|
||||
#include <zircon/process.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
|
@ -32,6 +32,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_
|
||||
|
Reference in New Issue
Block a user