2019-01-10 19:41:51 +00:00
|
|
|
#include <util/threading.hpp>
|
2019-07-09 00:06:22 +00:00
|
|
|
|
|
|
|
#include <util/logger.hpp>
|
|
|
|
|
|
|
|
#ifdef POSIX
|
|
|
|
#include <pthread.h>
|
2019-07-11 15:07:16 +00:00
|
|
|
#if defined(__FreeBSD__)
|
2019-07-10 16:46:21 +00:00
|
|
|
#include <pthread_np.h>
|
|
|
|
#endif
|
2019-07-09 00:06:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
|
|
|
void
|
|
|
|
SetThreadName(const std::string& name)
|
|
|
|
{
|
|
|
|
#ifdef POSIX
|
2019-07-11 15:07:16 +00:00
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
/* on free bsd this function has void return type */
|
2019-07-12 12:31:37 +00:00
|
|
|
pthread_set_name_np(pthread_self(), name.c_str());
|
2019-07-09 00:06:22 +00:00
|
|
|
#else
|
2019-07-11 15:07:16 +00:00
|
|
|
#if defined(__MACH__)
|
|
|
|
const int rc = pthread_setname_np(name.c_str());
|
|
|
|
#elif defined(__linux__)
|
2019-07-09 00:06:22 +00:00
|
|
|
const int rc = pthread_setname_np(pthread_self(), name.c_str());
|
2019-07-11 15:07:16 +00:00
|
|
|
#else
|
|
|
|
#error "unsupported platform"
|
2019-07-10 22:03:52 +00:00
|
|
|
#endif
|
2019-07-09 00:06:22 +00:00
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
LogError("Failed to set thread name to ", name, " errno = ", rc,
|
|
|
|
" errstr = ", strerror(rc));
|
|
|
|
}
|
2019-07-11 15:07:16 +00:00
|
|
|
#endif
|
2019-07-09 00:06:22 +00:00
|
|
|
#else
|
|
|
|
LogInfo("Thread name setting not supported on this platform");
|
|
|
|
(void)name;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} // namespace util
|
|
|
|
} // namespace llarp
|