2016-12-24 01:03:10 +00:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#include <pthread.h>
|
|
|
|
#elif defined(__FreeBSD__)
|
2016-10-26 22:27:38 +00:00
|
|
|
#include <pthread.h>
|
2016-12-24 01:03:10 +00:00
|
|
|
#include <pthread_np.h>
|
|
|
|
#else
|
|
|
|
#include <sys/prctl.h>
|
2016-10-26 22:27:38 +00:00
|
|
|
#endif
|
2016-12-24 01:03:10 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Exception.h>
|
|
|
|
#include <Common/setThreadName.h>
|
2015-09-24 18:54:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
void setThreadName(const char * name)
|
|
|
|
{
|
2016-12-24 01:03:10 +00:00
|
|
|
#if defined(__FreeBSD__)
|
2017-04-01 07:20:54 +00:00
|
|
|
pthread_set_name_np(pthread_self(), name);
|
|
|
|
return;
|
2016-12-24 01:03:10 +00:00
|
|
|
|
|
|
|
#elif defined(__APPLE__)
|
2017-04-01 07:20:54 +00:00
|
|
|
if (0 != pthread_setname_np(name))
|
2016-12-24 01:03:10 +00:00
|
|
|
#else
|
2017-04-01 07:20:54 +00:00
|
|
|
if (0 != prctl(PR_SET_NAME, name, 0, 0, 0))
|
2016-10-26 22:27:38 +00:00
|
|
|
#endif
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::throwFromErrno("Cannot set thread name with prctl(PR_SET_NAME...)");
|
2015-09-24 18:54:21 +00:00
|
|
|
}
|