using namespace icinga;
+int ThreadPool::m_NextID = 1;
+
ThreadPool::ThreadPool(void)
- : m_WaitTime(0), m_ServiceTime(0),
+ : m_ID(m_NextID++), m_WaitTime(0), m_ServiceTime(0),
m_TaskCount(0), m_Stopped(false)
{
for (int i = 0; i < 2; i++)
void ThreadPool::QueueThreadProc(int tid)
{
std::ostringstream idbuf;
- idbuf << "TP " << this << " Worker #" << tid;
+ idbuf << "TP #" << m_ID << " Worker #" << tid;
Utility::SetThreadName(idbuf.str());
for (;;) {
void ThreadPool::ManagerThreadProc(void)
{
std::ostringstream idbuf;
- idbuf << "TP " << this << " Manager";
+ idbuf << "TP #" << m_ID << " Manager";
Utility::SetThreadName(idbuf.str());
for (;;) {
void ThreadPool::StatsThreadProc(void)
{
std::ostringstream idbuf;
- idbuf << "TP " << this << " Stats";
+ idbuf << "TP #" << m_ID << " Stats";
Utility::SetThreadName(idbuf.str());
for (;;) {
void Utility::SetThreadName(const String& name)
{
m_ThreadName.reset(new String(name));
+
+#ifdef _WIN32
+ THREADNAME_INFO info;
+ info.dwType = 0x1000;
+ info.szName = name.CStr();
+ info.dwThreadID = -1;
+ info.dwFlags = 0;
+
+ __try {
+ RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info);
+ } __except(EXCEPTION_EXECUTE_HANDLER) {
+ /* Nothing to do here. */
+ }
+#endif /* _WIN32 */
+
+#ifdef __APPLE__
+ pthread_setname_np(name.CStr());
+#endif /* __APPLE__ */
+
+#ifdef __linux__
+ String tname = name.SubStr(0, 15);
+ pthread_setname_np(pthread_self(), tname.CStr());
+#endif /* __linux__ */
}
String Utility::GetThreadName(void)