mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Optimize lock state combining.
There are four possible lock states: 1. Nothing 2. HasLock 3. HasBlockingLock 4. WaitLock The previous switch was implementing the following state transition: s\n| 1 | 2 | 3 | 4 ---+---+---+---+--- 1 | 1 | 2 | 3 | 4 ---+---+---+---+--- 2 | 2 | 2 | 3 | 4 ---+---+---+---+--- 3 | 3 | 3 | 3 | 4 ---+---+---+---+--- 4 | 4 | 4 | 4 | 4 As can be seen, the switch effectively searches for the highest state possible. This change implements it as such.
This commit is contained in:
parent
c044884dd9
commit
91758423cd
@ -1,5 +1,6 @@
|
|||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
|
# include <intrin.h>
|
||||||
#else
|
#else
|
||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
@ -2745,10 +2746,10 @@ static inline bool AreOtherWaiting( uint64_t bitlist, uint8_t thread )
|
|||||||
|
|
||||||
enum class LockState
|
enum class LockState
|
||||||
{
|
{
|
||||||
Nothing,
|
Nothing = 1 << 0,
|
||||||
HasLock, // green
|
HasLock = 1 << 1, // green
|
||||||
HasBlockingLock, // yellow
|
HasBlockingLock = 1 << 2, // yellow
|
||||||
WaitLock // red
|
WaitLock = 1 << 3, // red
|
||||||
};
|
};
|
||||||
|
|
||||||
static Vector<LockEvent*>::iterator GetNextLockEvent( const Vector<LockEvent*>::iterator& it, const Vector<LockEvent*>::iterator& end, LockState state, LockState& nextState, uint8_t thread )
|
static Vector<LockEvent*>::iterator GetNextLockEvent( const Vector<LockEvent*>::iterator& it, const Vector<LockEvent*>::iterator& end, LockState state, LockState& nextState, uint8_t thread )
|
||||||
@ -2848,20 +2849,22 @@ static Vector<LockEvent*>::iterator GetNextLockEvent( const Vector<LockEvent*>::
|
|||||||
|
|
||||||
static LockState CombineLockState( LockState state, LockState next )
|
static LockState CombineLockState( LockState state, LockState next )
|
||||||
{
|
{
|
||||||
switch( state )
|
unsigned val = (unsigned)state | (unsigned)next;
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
DWORD ret;
|
||||||
|
_BitScanReverse( &ret, val );
|
||||||
|
return (LockState)( 1 << ret );
|
||||||
|
#else
|
||||||
|
unsigned ret = 1;
|
||||||
|
val >>= 1;
|
||||||
|
while( val )
|
||||||
{
|
{
|
||||||
case LockState::WaitLock:
|
ret <<= 1;
|
||||||
return LockState::WaitLock;
|
val >>= 1;
|
||||||
case LockState::HasBlockingLock:
|
|
||||||
return next == LockState::WaitLock ? next : state;
|
|
||||||
case LockState::HasLock:
|
|
||||||
return next == LockState::Nothing ? state : next;
|
|
||||||
case LockState::Nothing:
|
|
||||||
return next;
|
|
||||||
default:
|
|
||||||
assert( false );
|
|
||||||
return LockState::Nothing;
|
|
||||||
}
|
}
|
||||||
|
return (LockState)ret;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, int _offset, LockHighlight& highlight )
|
int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, int _offset, LockHighlight& highlight )
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user