Move SetCurrentThreadName to platform_thread.* in rtc_base_approved,
update all webrtc and libjingle code to use the same function and remove extra implementations. BUG= R=andresp@webrtc.org Review URL: https://webrtc-codereview.appspot.com/55439004 Cr-Commit-Position: refs/heads/master@{#9205}
This commit is contained in:
parent
bd1bc47395
commit
ea14f0ac11
@ -10,9 +10,12 @@
|
||||
|
||||
#include "webrtc/base/platform_thread.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
|
||||
#if defined(WEBRTC_LINUX)
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
@ -54,4 +57,26 @@ bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void SetCurrentThreadName(const char* name) {
|
||||
DCHECK(strlen(name) < 64);
|
||||
#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 rtc
|
||||
|
||||
@ -35,6 +35,9 @@ 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 // WEBRTC_BASE_PLATFORM_THREAD_H_
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
#include "webrtc/base/common.h"
|
||||
#include "webrtc/base/logging.h"
|
||||
#include "webrtc/base/platform_thread.h"
|
||||
#include "webrtc/base/stringutils.h"
|
||||
#include "webrtc/base/timeutils.h"
|
||||
|
||||
@ -350,41 +351,10 @@ void Thread::AssertBlockingIsAllowedOnCurrentThread() {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(WEBRTC_WIN)
|
||||
// As seen on MSDN.
|
||||
// http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.71).aspx
|
||||
#define MSDEV_SET_THREAD_NAME 0x406D1388
|
||||
typedef struct tagTHREADNAME_INFO {
|
||||
DWORD dwType;
|
||||
LPCSTR szName;
|
||||
DWORD dwThreadID;
|
||||
DWORD dwFlags;
|
||||
} THREADNAME_INFO;
|
||||
|
||||
void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName) {
|
||||
THREADNAME_INFO info;
|
||||
info.dwType = 0x1000;
|
||||
info.szName = szThreadName;
|
||||
info.dwThreadID = dwThreadID;
|
||||
info.dwFlags = 0;
|
||||
|
||||
__try {
|
||||
RaiseException(MSDEV_SET_THREAD_NAME, 0, sizeof(info) / sizeof(DWORD),
|
||||
reinterpret_cast<ULONG_PTR*>(&info));
|
||||
}
|
||||
__except(EXCEPTION_CONTINUE_EXECUTION) {
|
||||
}
|
||||
}
|
||||
#endif // WEBRTC_WIN
|
||||
|
||||
void* Thread::PreRun(void* pv) {
|
||||
ThreadInit* init = static_cast<ThreadInit*>(pv);
|
||||
ThreadManager::Instance()->SetCurrentThread(init->thread);
|
||||
#if defined(WEBRTC_WIN)
|
||||
SetThreadName(GetCurrentThreadId(), init->thread->name_.c_str());
|
||||
#elif defined(WEBRTC_POSIX)
|
||||
// TODO: See if naming exists for pthreads.
|
||||
#endif
|
||||
rtc::SetCurrentThreadName(init->thread->name_.c_str());
|
||||
#if __has_feature(objc_arc)
|
||||
@autoreleasepool
|
||||
#elif defined(WEBRTC_MAC)
|
||||
|
||||
@ -454,18 +454,4 @@ bool GetCurrentProcessIntegrityLevel(int* level) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SetCurrentThreadName(const char* name) {
|
||||
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) {
|
||||
}
|
||||
}
|
||||
} // namespace rtc
|
||||
|
||||
@ -126,9 +126,6 @@ inline bool IsCurrentProcessLowIntegrity() {
|
||||
|
||||
bool AdjustCurrentProcessPrivilege(const TCHAR* privilege, bool to_enable);
|
||||
|
||||
// Sets the current thread name for the windows debugger.
|
||||
void SetCurrentThreadName(const char* name);
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // WEBRTC_WIN
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
#include <strsafe.h>
|
||||
#include <uuids.h>
|
||||
|
||||
#include "webrtc/base/platform_thread.h"
|
||||
#include "webrtc/modules/audio_device/audio_device_utility.h"
|
||||
#include "webrtc/system_wrappers/interface/sleep.h"
|
||||
#include "webrtc/system_wrappers/interface/trace.h"
|
||||
@ -3389,7 +3390,7 @@ DWORD AudioDeviceWindowsCore::DoRenderThread()
|
||||
return 1;
|
||||
}
|
||||
|
||||
_SetThreadName(0, "webrtc_core_audio_render_thread");
|
||||
rtc::SetCurrentThreadName("webrtc_core_audio_render_thread");
|
||||
|
||||
// Use Multimedia Class Scheduler Service (MMCSS) to boost the thread priority.
|
||||
//
|
||||
@ -3666,7 +3667,7 @@ DWORD AudioDeviceWindowsCore::InitCaptureThreadPriority()
|
||||
{
|
||||
_hMmTask = NULL;
|
||||
|
||||
_SetThreadName(0, "webrtc_core_audio_capture_thread");
|
||||
rtc::SetCurrentThreadName("webrtc_core_audio_capture_thread");
|
||||
|
||||
// Use Multimedia Class Scheduler Service (MMCSS) to boost the thread
|
||||
// priority.
|
||||
@ -5069,30 +5070,6 @@ void AudioDeviceWindowsCore::_TraceCOMError(HRESULT hr) const
|
||||
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "%s", WideToUTF8(buf));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// _SetThreadName
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void AudioDeviceWindowsCore::_SetThreadName(DWORD dwThreadID, LPCSTR szThreadName)
|
||||
{
|
||||
// See http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.71).aspx for details on the code
|
||||
// in this function. Name of article is "Setting a Thread Name (Unmanaged)".
|
||||
|
||||
THREADNAME_INFO info;
|
||||
info.dwType = 0x1000;
|
||||
info.szName = szThreadName;
|
||||
info.dwThreadID = dwThreadID;
|
||||
info.dwFlags = 0;
|
||||
|
||||
__try
|
||||
{
|
||||
RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (ULONG_PTR *)&info );
|
||||
}
|
||||
__except (EXCEPTION_CONTINUE_EXECUTION)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// WideToUTF8
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@ -235,7 +235,6 @@ private: // thread functions
|
||||
static DWORD WINAPI SetCaptureVolumeThread(LPVOID context);
|
||||
DWORD DoSetCaptureVolumeThread();
|
||||
|
||||
void _SetThreadName(DWORD dwThreadID, LPCSTR szThreadName);
|
||||
void _Lock() { _critSect.Enter(); };
|
||||
void _UnLock() { _critSect.Leave(); };
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include "webrtc/modules/video_capture/windows/sink_filter_ds.h"
|
||||
|
||||
#include "webrtc/base/platform_thread.h"
|
||||
#include "webrtc/modules/video_capture/windows/help_functions_ds.h"
|
||||
#include "webrtc/system_wrappers/interface/trace.h"
|
||||
|
||||
@ -328,24 +329,8 @@ CaptureInputPin::Receive ( IN IMediaSample * pIMediaSample )
|
||||
HANDLE handle= GetCurrentThread();
|
||||
SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST);
|
||||
_threadHandle = handle;
|
||||
// See http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.71).aspx for details on the code
|
||||
// in this function. Name od article is "Setting a Thread Name (Unmanaged)".
|
||||
|
||||
THREADNAME_INFO info;
|
||||
info.dwType = 0x1000;
|
||||
info.szName = "capture_thread";
|
||||
info.dwThreadID = (DWORD)-1;
|
||||
info.dwFlags = 0;
|
||||
|
||||
__try
|
||||
{
|
||||
RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD),
|
||||
(DWORD_PTR*)&info );
|
||||
}
|
||||
__except (EXCEPTION_CONTINUE_EXECUTION)
|
||||
{
|
||||
}
|
||||
|
||||
rtc::SetCurrentThreadName("webrtc_video_capture");
|
||||
}
|
||||
|
||||
reinterpret_cast <CaptureSinkFilter *>(m_pFilter)->LockReceive();
|
||||
|
||||
@ -17,12 +17,11 @@
|
||||
#ifdef WEBRTC_LINUX
|
||||
#include <linux/unistd.h>
|
||||
#include <sched.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/base/platform_thread.h"
|
||||
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
|
||||
#include "webrtc/system_wrappers/interface/event_wrapper.h"
|
||||
#include "webrtc/system_wrappers/interface/sleep.h"
|
||||
@ -152,11 +151,7 @@ void ThreadPosix::Run() {
|
||||
if (!name_.empty()) {
|
||||
// Setting the thread name may fail (harmlessly) if running inside a
|
||||
// sandbox. Ignore failures if they happen.
|
||||
#if defined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID)
|
||||
prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(name_.c_str()));
|
||||
#elif defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
|
||||
pthread_setname_np(name_.substr(0, 63).c_str());
|
||||
#endif
|
||||
rtc::SetCurrentThreadName(name_.substr(0, 63).c_str());
|
||||
}
|
||||
|
||||
// It's a requirement that for successful thread creation that the run
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/base/platform_thread.h"
|
||||
#include "webrtc/system_wrappers/interface/trace.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -22,36 +23,6 @@ namespace {
|
||||
void CALLBACK RaiseFlag(ULONG_PTR param) {
|
||||
*reinterpret_cast<bool*>(param) = true;
|
||||
}
|
||||
|
||||
// TODO(tommi): This is borrowed from webrtc/base/thread.cc, but we can't
|
||||
// include thread.h from here since thread.h pulls in libjingle dependencies.
|
||||
// Would be good to consolidate.
|
||||
|
||||
// As seen on MSDN.
|
||||
// http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.71).aspx
|
||||
#define MSDEV_SET_THREAD_NAME 0x406D1388
|
||||
typedef struct tagTHREADNAME_INFO {
|
||||
DWORD dwType;
|
||||
LPCSTR szName;
|
||||
DWORD dwThreadID;
|
||||
DWORD dwFlags;
|
||||
} THREADNAME_INFO;
|
||||
|
||||
void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName) {
|
||||
THREADNAME_INFO info;
|
||||
info.dwType = 0x1000;
|
||||
info.szName = szThreadName;
|
||||
info.dwThreadID = dwThreadID;
|
||||
info.dwFlags = 0;
|
||||
|
||||
__try {
|
||||
RaiseException(MSDEV_SET_THREAD_NAME, 0, sizeof(info) / sizeof(DWORD),
|
||||
reinterpret_cast<ULONG_PTR*>(&info));
|
||||
}
|
||||
__except(EXCEPTION_CONTINUE_EXECUTION) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ThreadWindows::ThreadWindows(ThreadRunFunction func, void* obj,
|
||||
@ -120,7 +91,7 @@ bool ThreadWindows::SetPriority(ThreadPriority priority) {
|
||||
|
||||
void ThreadWindows::Run() {
|
||||
if (!name_.empty())
|
||||
SetThreadName(static_cast<DWORD>(-1), name_.c_str());
|
||||
rtc::SetCurrentThreadName(name_.c_str());
|
||||
|
||||
do {
|
||||
// The interface contract of Start/Stop is that for a successfull call to
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user