From 3b67032adbfdb1d71e3a5ee3b16a7096ceb14b12 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sun, 23 Dec 2018 14:19:30 -0800 Subject: [PATCH] add missing src files (IXSetThreadName.{cpp,h}) ... --- ixwebsocket/IXSetThreadName.cpp | 31 +++++++++++++++++++++++++++++++ ixwebsocket/IXSetThreadName.h | 13 +++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 ixwebsocket/IXSetThreadName.cpp create mode 100644 ixwebsocket/IXSetThreadName.h diff --git a/ixwebsocket/IXSetThreadName.cpp b/ixwebsocket/IXSetThreadName.cpp new file mode 100644 index 00000000..5147c14c --- /dev/null +++ b/ixwebsocket/IXSetThreadName.cpp @@ -0,0 +1,31 @@ +/* + * IXSetThreadName.cpp + * Author: Benjamin Sergeant + * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. + */ +#include "IXSetThreadName.h" +#include + +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 + } +} diff --git a/ixwebsocket/IXSetThreadName.h b/ixwebsocket/IXSetThreadName.h new file mode 100644 index 00000000..4493c736 --- /dev/null +++ b/ixwebsocket/IXSetThreadName.h @@ -0,0 +1,13 @@ +/* + * IXSetThreadName.h + * Author: Benjamin Sergeant + * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. + */ +#pragma once +#include + +namespace ix +{ + void setThreadName(const std::string& name); +} +