From 0b816ce0b7ce70c6816cb3de2477c2ded0cc38b4 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 16 Dec 2018 20:37:48 +0100 Subject: [PATCH] Add lock termination event. --- client/TracyLock.hpp | 36 ++++++++++++++++++++++++++++++++++++ common/TracyQueue.hpp | 10 ++++++++++ 2 files changed, 46 insertions(+) diff --git a/client/TracyLock.hpp b/client/TracyLock.hpp index cf4d38c6..4f995a3e 100644 --- a/client/TracyLock.hpp +++ b/client/TracyLock.hpp @@ -46,6 +46,24 @@ public: Lockable( const Lockable& ) = delete; Lockable& operator=( const Lockable& ) = delete; + ~Lockable() + { + Magic magic; + auto& token = s_token.ptr; + auto& tail = token->get_tail_index(); + auto item = token->enqueue_begin( magic ); + MemWrite( &item->hdr.type, QueueType::LockTerminate ); + MemWrite( &item->lockTerminate.id, m_id ); + MemWrite( &item->lockTerminate.time, Profiler::GetTime() ); + MemWrite( &item->lockTerminate.type, LockType::Lockable ); + +#ifdef TRACY_ON_DEMAND + s_profiler.DeferItem( *item ); +#endif + + tail.store( magic + 1, std::memory_order_release ); + } + tracy_force_inline void lock() { #ifdef TRACY_ON_DEMAND @@ -221,6 +239,24 @@ public: SharedLockable( const SharedLockable& ) = delete; SharedLockable& operator=( const SharedLockable& ) = delete; + ~SharedLockable() + { + Magic magic; + auto& token = s_token.ptr; + auto& tail = token->get_tail_index(); + auto item = token->enqueue_begin( magic ); + MemWrite( &item->hdr.type, QueueType::LockTerminate ); + MemWrite( &item->lockTerminate.id, m_id ); + MemWrite( &item->lockTerminate.time, Profiler::GetTime() ); + MemWrite( &item->lockTerminate.type, LockType::SharedLockable ); + +#ifdef TRACY_ON_DEMAND + s_profiler.DeferItem( *item ); +#endif + + tail.store( magic + 1, std::memory_order_release ); + } + tracy_force_inline void lock() { #ifdef TRACY_ON_DEMAND diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index 31bcc3a2..8cdfec7d 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -26,6 +26,7 @@ enum class QueueType : uint8_t FrameMarkMsgEnd, SourceLocation, LockAnnounce, + LockTerminate, LockWait, LockObtain, LockRelease, @@ -114,6 +115,13 @@ struct QueueLockAnnounce LockType type; }; +struct QueueLockTerminate +{ + uint32_t id; + int64_t time; + LockType type; +}; + struct QueueLockWait { uint32_t id; @@ -265,6 +273,7 @@ struct QueueItem QueueSourceLocation srcloc; QueueZoneText zoneText; QueueLockAnnounce lockAnnounce; + QueueLockTerminate lockTerminate; QueueLockWait lockWait; QueueLockObtain lockObtain; QueueLockRelease lockRelease; @@ -308,6 +317,7 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueFrameMark ), // end sizeof( QueueHeader ) + sizeof( QueueSourceLocation ), sizeof( QueueHeader ) + sizeof( QueueLockAnnounce ), + sizeof( QueueHeader ) + sizeof( QueueLockTerminate ), sizeof( QueueHeader ) + sizeof( QueueLockWait ), sizeof( QueueHeader ) + sizeof( QueueLockObtain ), sizeof( QueueHeader ) + sizeof( QueueLockRelease ),