Core/Thread: Add posibility of setting thread name
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user