From f78807100320ffdda3955da33032b7c043bed643 Mon Sep 17 00:00:00 2001 From: Sergey Yagovtsev Date: Sun, 27 Nov 2016 14:26:00 +0300 Subject: [PATCH] Check thread expired on linux and add new message in easy_net --- include/easy/easy_net.h | 1 + src/profile_manager.cpp | 22 +++++++++++++++++----- src/profile_manager.h | 5 +++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/easy/easy_net.h b/include/easy/easy_net.h index a703740..7f12f30 100644 --- a/include/easy/easy_net.h +++ b/include/easy/easy_net.h @@ -64,6 +64,7 @@ enum MessageType : uint8_t MESSAGE_TYPE_EVENT_TRACING_STATUS, MESSAGE_TYPE_EVENT_TRACING_PRIORITY, + MESSAGE_TYPE_CHECK_CONNECTION }; struct Message diff --git a/src/profile_manager.cpp b/src/profile_manager.cpp index b58b07f..426174d 100644 --- a/src/profile_manager.cpp +++ b/src/profile_manager.cpp @@ -47,6 +47,10 @@ #include "event_trace_win.h" #include "current_time.h" +#ifndef _WIN32 +#include +#endif + ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// @@ -305,9 +309,10 @@ public: ////////////////////////////////////////////////////////////////////////// -ThreadStorage::ThreadStorage() : id(getCurrentThreadId()), allowChildren(true), named(false) +ThreadStorage::ThreadStorage() : id(getCurrentThreadId()), allowChildren(true), named(false), pthread_id(pthread_self()) { expired = ATOMIC_VAR_INIT(false); + } void ThreadStorage::storeBlock(const profiler::Block& block) @@ -660,7 +665,7 @@ bool ProfileManager::checkThreadExpired(ThreadStorage& _registeredThread) DWORD exitCode = 0; auto hThread = OpenThread(THREAD_QUERY_LIMITED_INFORMATION, FALSE, _registeredThread.id); - if (hThread == nullptr || GetExitCodeThread(hThread, &exitCode) == FALSE || exitCode != STILL_ACTIVE) + if (hThread == nullptr || GetExitCodeThread(hThread, &exitCode) == FALSE || exitCode != STILL_ACTIVE) { // Thread has been expired _registeredThread.expired.store(true, std::memory_order_release); @@ -671,14 +676,14 @@ bool ProfileManager::checkThreadExpired(ThreadStorage& _registeredThread) if (hThread != nullptr) CloseHandle(hThread); - + return false; #else - // TODO: Check thread for Linux + return pthread_kill(_registeredThread.pthread_id, 0) != 0; #endif - return false; + } ////////////////////////////////////////////////////////////////////////// @@ -976,6 +981,13 @@ void ProfileManager::listen() switch (message->type) { + case profiler::net::MESSAGE_TYPE_CHECK_CONNECTION: + { +#ifdef EASY_DEBUG_NET_PRINT + printf("receive MESSAGE_TYPE_CHECK_CONNECTION\n"); +#endif + break; + } case profiler::net::MESSAGE_TYPE_REQUEST_START_CAPTURE: { #ifdef EASY_DEBUG_NET_PRINT diff --git a/src/profile_manager.h b/src/profile_manager.h index cfaa602..114a68c 100644 --- a/src/profile_manager.h +++ b/src/profile_manager.h @@ -309,6 +309,11 @@ struct ThreadStorage BlocksList, SIZEOF_CSWITCH * (uint16_t)128U> blocks; BlocksList sync; std::string name; + +#ifndef _WIN32 + const pthread_t pthread_id; +#endif + const profiler::thread_id_t id; std::atomic_bool expired; bool allowChildren;