0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

Static thread local

This commit is contained in:
Sergey Yagovtsev 2018-09-18 22:50:51 +03:00
parent 99b761375b
commit 53289cec81
7 changed files with 24 additions and 15 deletions

View File

@ -63,7 +63,7 @@ inline profiler::thread_id_t getCurrentThreadId()
#elif defined(__APPLE__) #elif defined(__APPLE__)
# if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_6) || \ # 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) (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) if (!_id)
pthread_threadid_np(NULL, &_id); pthread_threadid_np(NULL, &_id);
return (profiler::thread_id_t)_id; return (profiler::thread_id_t)_id;

View File

@ -252,7 +252,7 @@ and creates "ThreadFinished" profiler event.
\ingroup profiler \ingroup profiler
*/ */
# define EASY_THREAD_SCOPE(name)\ # 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__);\ ::profiler::ThreadGuard EASY_TOKEN_CONCATENATE(unique_profiler_thread_guard, __LINE__);\
if (!EASY_TOKEN_CONCATENATE(unique_profiler_thread_name, __LINE__))\ if (!EASY_TOKEN_CONCATENATE(unique_profiler_thread_name, __LINE__))\
EASY_TOKEN_CONCATENATE(unique_profiler_thread_name, __LINE__) = ::profiler::registerThreadScoped(name,\ EASY_TOKEN_CONCATENATE(unique_profiler_thread_name, __LINE__) = ::profiler::registerThreadScoped(name,\

View File

@ -156,15 +156,15 @@ EASY_CONSTEXPR uint8_t FORCE_ON_FLAG = profiler::FORCE_ON & ~profiler::ON;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
EASY_THREAD_LOCAL static ::ThreadStorage* THIS_THREAD = nullptr; static EASY_THREAD_LOCAL ::ThreadStorage* THIS_THREAD = nullptr;
EASY_THREAD_LOCAL static bool THIS_THREAD_IS_MAIN = false; static EASY_THREAD_LOCAL bool THIS_THREAD_IS_MAIN = false;
EASY_THREAD_LOCAL static profiler::timestamp_t THIS_THREAD_FRAME_T_MAX = 0ULL; static EASY_THREAD_LOCAL profiler::timestamp_t THIS_THREAD_FRAME_T_MAX = 0ULL;
EASY_THREAD_LOCAL static profiler::timestamp_t THIS_THREAD_FRAME_T_CUR = 0ULL; static EASY_THREAD_LOCAL profiler::timestamp_t THIS_THREAD_FRAME_T_CUR = 0ULL;
EASY_THREAD_LOCAL static profiler::timestamp_t THIS_THREAD_FRAME_T_ACC = 0ULL; static EASY_THREAD_LOCAL profiler::timestamp_t THIS_THREAD_FRAME_T_ACC = 0ULL;
EASY_THREAD_LOCAL static uint32_t THIS_THREAD_N_FRAMES = 0; static EASY_THREAD_LOCAL uint32_t THIS_THREAD_N_FRAMES = 0;
EASY_THREAD_LOCAL static bool THIS_THREAD_FRAME_T_RESET_MAX = false; static EASY_THREAD_LOCAL bool THIS_THREAD_FRAME_T_RESET_MAX = false;
EASY_THREAD_LOCAL static bool THIS_THREAD_FRAME_T_RESET_AVG = false; static EASY_THREAD_LOCAL bool THIS_THREAD_FRAME_T_RESET_AVG = false;
#ifdef EASY_CXX11_TLS_AVAILABLE #ifdef EASY_CXX11_TLS_AVAILABLE
thread_local static profiler::ThreadGuard THIS_THREAD_GUARD; // thread guard for monitoring thread life time thread_local static profiler::ThreadGuard THIS_THREAD_GUARD; // thread guard for monitoring thread life time

View File

@ -139,7 +139,7 @@ public:
bool mouseDoubleClick(const QPointF& scenePos); bool mouseDoubleClick(const QPointF& scenePos);
void mouseLeave(); void mouseLeave();
bool contains(const QPointF& scenePos) const; bool contains(const QPointF& scenePos) const override;
signals: signals:

View File

@ -433,6 +433,8 @@ void DescriptorsTreeWidget::build()
case ::profiler::BlockType::Value: case ::profiler::BlockType::Value:
item->setType(DescriptorsTreeItem::Type::Value); item->setType(DescriptorsTreeItem::Type::Value);
break; break;
case ::profiler::BlockType::TypesCount: break;
} }
item->setFont(DESC_COL_STATUS, f); item->setFont(DESC_COL_STATUS, f);

View File

@ -68,11 +68,17 @@
#endif #endif
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
#define EASY_INIT_ATOMIC(v) v
#if defined (_WIN32)
#undef EASY_INIT_ATOMIC
#define EASY_INIT_ATOMIC(v) {v}
#endif
TreeWidgetLoader::TreeWidgetLoader() TreeWidgetLoader::TreeWidgetLoader()
: m_bDone(false) : m_bDone(EASY_INIT_ATOMIC(false))
, m_bInterrupt(false) , m_bInterrupt(EASY_INIT_ATOMIC(false))
, m_progress(0) , m_progress(EASY_INIT_ATOMIC(0))
, m_mode(TreeMode::Full) , m_mode(TreeMode::Full)
{ {
} }

View File

@ -269,7 +269,8 @@ int main(int argc, char* argv[])
cv.notify_all(); cv.notify_all();
#ifndef SAMPLE_NETWORK_TEST #ifndef SAMPLE_NETWORK_TEST
std::atomic_bool stop(false); std::atomic_bool stop;
stop = false;
auto frame_time_printer_thread = std::thread([&stop]() auto frame_time_printer_thread = std::thread([&stop]()
{ {
while (!stop.load(std::memory_order_acquire)) while (!stop.load(std::memory_order_acquire))