[osal]: add windows pthread_setname_np

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@806 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2016-05-24 06:16:58 +00:00
parent a2b391de18
commit 91ef4a9dda

View File

@@ -88,12 +88,48 @@ void MppThread::stop()
}
#if defined(_WIN32) && !defined(__MINGW32CE__)
//
// Usage: SetThreadName ((DWORD)-1, "MainThread");
//
#include <windows.h>
const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
void SetThreadName(DWORD dwThreadID, const char* threadName) {
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = threadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
#pragma warning(push)
#pragma warning(disable: 6320 6322)
__try{
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
}
__except (EXCEPTION_EXECUTE_HANDLER){
}
#pragma warning(pop)
}
/*
* add pthread_setname_np for windows
*/
int pthread_setname_np(pthread_t thread, const char *name)
{
DWORD dwThreadID = pthread_getw32threadid_np(thread);
SetThreadName(dwThreadID, name);
return 0;
}
#endif