add missing src files (IXSetThreadName.{cpp,h}) ...

This commit is contained in:
Benjamin Sergeant 2018-12-23 14:19:30 -08:00
parent 2d46a0605b
commit 3b67032adb
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,31 @@
/*
* IXSetThreadName.cpp
* Author: Benjamin Sergeant
* Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
*/
#include "IXSetThreadName.h"
#include <pthread.h>
namespace ix
{
void setThreadName(const std::string& name)
{
#if defined(__linux__)
//
// Linux only reserve 16 bytes for its thread names
// See prctl and PR_SET_NAME property in
// http://man7.org/linux/man-pages/man2/prctl.2.html
//
pthread_setname_np(pthread_self(),
name.substr(0, 15).c_str());
#elif defined(__APPLE__)
//
// Apple is more generous with 64 chars.
// notice how the Apple version does not take a pthread_t argument
//
pthread_setname_np(name.substr(0, 63).c_str());
#elif
#error("Unsupported platform");
#endif
}
}

View File

@ -0,0 +1,13 @@
/*
* IXSetThreadName.h
* Author: Benjamin Sergeant
* Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
*/
#pragma once
#include <string>
namespace ix
{
void setThreadName(const std::string& name);
}