From 53289cec812fc61b1851c16fe38f3dbd3993ea8f Mon Sep 17 00:00:00 2001 From: Sergey Yagovtsev Date: Tue, 18 Sep 2018 22:50:51 +0300 Subject: [PATCH] Static thread local --- easy_profiler_core/current_thread.h | 2 +- easy_profiler_core/include/easy/profiler.h | 2 +- easy_profiler_core/profile_manager.cpp | 16 ++++++++-------- profiler_gui/blocks_graphics_view.h | 2 +- profiler_gui/descriptors_tree_widget.cpp | 2 ++ profiler_gui/tree_widget_loader.cpp | 12 +++++++++--- sample/main.cpp | 3 ++- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/easy_profiler_core/current_thread.h b/easy_profiler_core/current_thread.h index fe465c1..b9ffe73 100644 --- a/easy_profiler_core/current_thread.h +++ b/easy_profiler_core/current_thread.h @@ -63,7 +63,7 @@ inline profiler::thread_id_t getCurrentThreadId() #elif defined(__APPLE__) # if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_6) || \ (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0) - EASY_THREAD_LOCAL static uint64_t _id = 0; + static EASY_THREAD_LOCAL uint64_t _id = 0; if (!_id) pthread_threadid_np(NULL, &_id); return (profiler::thread_id_t)_id; diff --git a/easy_profiler_core/include/easy/profiler.h b/easy_profiler_core/include/easy/profiler.h index b059813..b9f7b57 100644 --- a/easy_profiler_core/include/easy/profiler.h +++ b/easy_profiler_core/include/easy/profiler.h @@ -252,7 +252,7 @@ and creates "ThreadFinished" profiler event. \ingroup profiler */ # define EASY_THREAD_SCOPE(name)\ - EASY_THREAD_LOCAL static const char* EASY_TOKEN_CONCATENATE(unique_profiler_thread_name, __LINE__) = 0;\ + static EASY_THREAD_LOCAL const char* EASY_TOKEN_CONCATENATE(unique_profiler_thread_name, __LINE__) = 0;\ ::profiler::ThreadGuard EASY_TOKEN_CONCATENATE(unique_profiler_thread_guard, __LINE__);\ if (!EASY_TOKEN_CONCATENATE(unique_profiler_thread_name, __LINE__))\ EASY_TOKEN_CONCATENATE(unique_profiler_thread_name, __LINE__) = ::profiler::registerThreadScoped(name,\ diff --git a/easy_profiler_core/profile_manager.cpp b/easy_profiler_core/profile_manager.cpp index 3fe302d..45d641d 100644 --- a/easy_profiler_core/profile_manager.cpp +++ b/easy_profiler_core/profile_manager.cpp @@ -156,15 +156,15 @@ EASY_CONSTEXPR uint8_t FORCE_ON_FLAG = profiler::FORCE_ON & ~profiler::ON; ////////////////////////////////////////////////////////////////////////// -EASY_THREAD_LOCAL static ::ThreadStorage* THIS_THREAD = nullptr; -EASY_THREAD_LOCAL static bool THIS_THREAD_IS_MAIN = false; +static EASY_THREAD_LOCAL ::ThreadStorage* THIS_THREAD = nullptr; +static EASY_THREAD_LOCAL bool THIS_THREAD_IS_MAIN = false; -EASY_THREAD_LOCAL static profiler::timestamp_t THIS_THREAD_FRAME_T_MAX = 0ULL; -EASY_THREAD_LOCAL static profiler::timestamp_t THIS_THREAD_FRAME_T_CUR = 0ULL; -EASY_THREAD_LOCAL static profiler::timestamp_t THIS_THREAD_FRAME_T_ACC = 0ULL; -EASY_THREAD_LOCAL static uint32_t THIS_THREAD_N_FRAMES = 0; -EASY_THREAD_LOCAL static bool THIS_THREAD_FRAME_T_RESET_MAX = false; -EASY_THREAD_LOCAL static bool THIS_THREAD_FRAME_T_RESET_AVG = false; +static EASY_THREAD_LOCAL profiler::timestamp_t THIS_THREAD_FRAME_T_MAX = 0ULL; +static EASY_THREAD_LOCAL profiler::timestamp_t THIS_THREAD_FRAME_T_CUR = 0ULL; +static EASY_THREAD_LOCAL profiler::timestamp_t THIS_THREAD_FRAME_T_ACC = 0ULL; +static EASY_THREAD_LOCAL uint32_t THIS_THREAD_N_FRAMES = 0; +static EASY_THREAD_LOCAL bool THIS_THREAD_FRAME_T_RESET_MAX = false; +static EASY_THREAD_LOCAL bool THIS_THREAD_FRAME_T_RESET_AVG = false; #ifdef EASY_CXX11_TLS_AVAILABLE thread_local static profiler::ThreadGuard THIS_THREAD_GUARD; // thread guard for monitoring thread life time diff --git a/profiler_gui/blocks_graphics_view.h b/profiler_gui/blocks_graphics_view.h index 051486e..c948253 100644 --- a/profiler_gui/blocks_graphics_view.h +++ b/profiler_gui/blocks_graphics_view.h @@ -139,7 +139,7 @@ public: bool mouseDoubleClick(const QPointF& scenePos); void mouseLeave(); - bool contains(const QPointF& scenePos) const; + bool contains(const QPointF& scenePos) const override; signals: diff --git a/profiler_gui/descriptors_tree_widget.cpp b/profiler_gui/descriptors_tree_widget.cpp index f769981..d5ce2ca 100644 --- a/profiler_gui/descriptors_tree_widget.cpp +++ b/profiler_gui/descriptors_tree_widget.cpp @@ -433,6 +433,8 @@ void DescriptorsTreeWidget::build() case ::profiler::BlockType::Value: item->setType(DescriptorsTreeItem::Type::Value); break; + + case ::profiler::BlockType::TypesCount: break; } item->setFont(DESC_COL_STATUS, f); diff --git a/profiler_gui/tree_widget_loader.cpp b/profiler_gui/tree_widget_loader.cpp index 3dae2e0..a49d402 100644 --- a/profiler_gui/tree_widget_loader.cpp +++ b/profiler_gui/tree_widget_loader.cpp @@ -68,11 +68,17 @@ #endif ////////////////////////////////////////////////////////////////////////// +#define EASY_INIT_ATOMIC(v) v + +#if defined (_WIN32) +#undef EASY_INIT_ATOMIC +#define EASY_INIT_ATOMIC(v) {v} +#endif TreeWidgetLoader::TreeWidgetLoader() - : m_bDone(false) - , m_bInterrupt(false) - , m_progress(0) + : m_bDone(EASY_INIT_ATOMIC(false)) + , m_bInterrupt(EASY_INIT_ATOMIC(false)) + , m_progress(EASY_INIT_ATOMIC(0)) , m_mode(TreeMode::Full) { } diff --git a/sample/main.cpp b/sample/main.cpp index 31f0a8d..dafa7e3 100644 --- a/sample/main.cpp +++ b/sample/main.cpp @@ -269,7 +269,8 @@ int main(int argc, char* argv[]) cv.notify_all(); #ifndef SAMPLE_NETWORK_TEST - std::atomic_bool stop(false); + std::atomic_bool stop; + stop = false; auto frame_time_printer_thread = std::thread([&stop]() { while (!stop.load(std::memory_order_acquire))