Removing xe_thread_t.

This commit is contained in:
Ben Vanik
2014-08-16 01:36:45 -07:00
parent bca49bed4b
commit 01f0b14250
12 changed files with 69 additions and 216 deletions

View File

@@ -12,6 +12,7 @@
#include <chrono>
#include <cstdint>
#include <string>
#include <poly/config.h>
@@ -25,6 +26,9 @@ uint64_t ticks();
// purposes only.
uint32_t current_thread_id();
// Sets the current thread name.
void set_name(const std::string& name);
// Yields the current thread to the scheduler. Maybe.
void Yield();

View File

@@ -24,6 +24,14 @@ uint32_t current_thread_id() {
return static_cast<uint32_t>(tid);
}
void set_name(const std::string& name) {
#if XE_LIKE_OSX
pthread_setname_np(name.c_str());
#else
pthread_setname_np(pthread_self(), name.c_str());
#endif // XE_LIKE_OSX
}
void Yield() { pthread_yield_np(); }
void Sleep(std::chrono::microseconds duration) {

View File

@@ -27,6 +27,36 @@ uint32_t current_thread_id() {
return static_cast<uint32_t>(GetCurrentThreadId());
}
// http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
#pragma pack(push, 8)
struct THREADNAME_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.
};
#pragma pack(pop)
void set_name(DWORD thread_id, const std::string& name) {
if (!IsDebuggerPresent()) {
return;
}
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name.c_str();
info.dwThreadID = thread_id;
info.dwFlags = 0;
__try {
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(ULONG_PTR),
reinterpret_cast<ULONG_PTR*>(&info));
}
__except(EXCEPTION_EXECUTE_HANDLER) {}
}
void set_name(const std::string& name) {
set_name(static_cast<DWORD>(-1), name);
}
void Yield() { SwitchToThread(); }
void Sleep(std::chrono::microseconds duration) {