Core/Thread: Add posibility of setting thread name

This commit is contained in:
Lynix
2017-06-20 08:16:08 +02:00
parent 4a1a335cee
commit 50a3f78f91
6 changed files with 128 additions and 13 deletions

View File

@@ -29,13 +29,22 @@ namespace Nz
pthread_join(m_handle, nullptr);
}
void* ThreadImpl::ThreadProc(void* userdata)
void ThreadImpl::SetName(const Nz::String& name)
{
Functor* func = static_cast<Functor*>(userdata);
func->Run();
delete func;
#ifdef __GNUC__
pthread_setname_np(m_handle, name.GetConstBuffer());
#else
NazaraWarning("Setting thread name is not supported on this platform");
#endif
}
return nullptr;
void ThreadImpl::SetCurrentName(const Nz::String& name)
{
#ifdef __GNUC__
pthread_setname_np(pthread_self(), name.GetConstBuffer());
#else
NazaraWarning("Setting current thread name is not supported on this platform");
#endif
}
void ThreadImpl::Sleep(UInt32 time)
@@ -56,4 +65,13 @@ namespace Nz
while (r == -1 && errno == EINTR);
}
}
void* ThreadImpl::ThreadProc(void* userdata)
{
Functor* func = static_cast<Functor*>(userdata);
func->Run();
delete func;
return nullptr;
}
}

View File

@@ -8,6 +8,11 @@
#define NAZARA_THREADIMPL_HPP
#include <Nazara/Prerequesites.hpp>
#ifdef __GNUC__
#define _GNU_SOURCE
#endif
#include <pthread.h>
namespace Nz
@@ -21,7 +26,9 @@ namespace Nz
void Detach();
void Join();
void SetName(const Nz::String& name);
static void SetCurrentName(const Nz::String& name);
static void Sleep(UInt32 time);
private: