Skip to content

Commit

Permalink
Merge pull request #108 from RaphaelIT7/patch-6
Browse files Browse the repository at this point in the history
[tier0] Fix a linux 64x vprof bug
  • Loading branch information
dimhotepus authored Dec 7, 2024
2 parents 76fe8e0 + bc5764e commit ee09a8e
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 62 deletions.
4 changes: 2 additions & 2 deletions engine/host_saverestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static bool HaveExactMap( const char *pszMapName )
static void FinishAsyncSave()
{
LOCAL_THREAD_LOCK();
SaveMsg( "FinishAsyncSave() (%d/%d)\n", ThreadInMainThread(), ThreadGetCurrentId() );
SaveMsg( "FinishAsyncSave() (%d/%lu)\n", ThreadInMainThread(), ThreadGetCurrentId() );
if ( g_AsyncSaveCallQueue.Count() )
{
g_AsyncSaveCallQueue.CallQueued();
Expand Down Expand Up @@ -628,7 +628,7 @@ int CSaveRestore::SaveGameSlot( const char *pSaveName, const char *pSaveComment,
Sys_Sleep( clamp( save_asyncdelay.GetInt(), 0, 3000 ) );
}

SaveMsg( "Start save... (%d/%d)\n", ThreadInMainThread(), ThreadGetCurrentId() );
SaveMsg( "Start save... (%d/%lu)\n", ThreadInMainThread(), ThreadGetCurrentId() );
VPROF_BUDGET( "SaveGameSlot", "Save" );
char hlPath[256], name[256], *pTokenData;
int tag, i, tokenSize;
Expand Down
2 changes: 1 addition & 1 deletion filesystem/QueuedLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct FileJob_t
int m_SubmitTag;
int m_nActualBytesRead;
LoaderError_t m_LoaderError;
unsigned int m_ThreadId;
ThreadId_t m_ThreadId;

unsigned int m_bFinished : 1;
unsigned int m_bFreeTargetAfterIO : 1;
Expand Down
2 changes: 1 addition & 1 deletion game/shared/collisionproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CDirtySpatialPartitionEntityList : public CAutoGameSystem, public IPartiti
private:
CTSListWithFreeList<CBaseHandle> m_DirtyEntities;
CThreadSpinRWLock m_partitionMutex;
uint32 m_partitionWriteId;
ThreadId_t m_partitionWriteId;
CThreadLocalInt<> m_readLockCount;
};

Expand Down
2 changes: 1 addition & 1 deletion gcsdk/jobmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ int CJobMgr::CountJobs() const
//-----------------------------------------------------------------------------
void CJobMgr::CheckThreadID()
{
uint unCurrentThread = ThreadGetCurrentId();
ThreadId_t unCurrentThread = ThreadGetCurrentId();

if ( m_unFrameFuncThreadID == 0 )
{
Expand Down
4 changes: 2 additions & 2 deletions materialsystem/cmaterialsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void CMaterialSystem::CleanUpErrorMaterial()
//-----------------------------------------------------------------------------
CMaterialSystem::CMaterialSystem()
{
m_nRenderThreadID = 0xFFFFFFFF;
m_nRenderThreadID = -1;
m_hAsyncLoadFileCache = NULL;
m_ShaderHInst = NULL;
m_ShaderAPIFactory = NULL;
Expand Down Expand Up @@ -3364,7 +3364,7 @@ void CMaterialSystem::ThreadExecuteQueuedContext( CMatQueuedRenderContext *pCont
m_pRenderContext.Set( &m_HardwareRenderContext );
pContext->EndQueue( true );
m_pRenderContext.Set( pSavedRenderContext );
m_nRenderThreadID = 0xFFFFFFFF;
m_nRenderThreadID = -1;
}

IThreadPool *CMaterialSystem::CreateMatQueueThreadPool()
Expand Down
6 changes: 3 additions & 3 deletions materialsystem/cmaterialsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ class CMaterialSystem : public CTier2AppSystem< IMaterialSystemInternal >, publi
MaterialLock_t Lock();
void Unlock( MaterialLock_t );
CMatCallQueue * GetRenderCallQueue();
uint GetRenderThreadId() const { return m_nRenderThreadID; }
ThreadId_t GetRenderThreadId() const { return m_nRenderThreadID; }
void UnbindMaterial( IMaterial *pMaterial );

IMaterialProxy *DetermineProxyReplacements( IMaterial *pMaterial, KeyValues *pFallbackKeyValues );
Expand Down Expand Up @@ -700,15 +700,15 @@ class CMaterialSystem : public CTier2AppSystem< IMaterialSystemInternal >, publi

const char * m_pForcedTextureLoadPathID;
FileCacheHandle_t m_hAsyncLoadFileCache;
uint m_nRenderThreadID;
ThreadId_t m_nRenderThreadID;
bool m_bAllocatingRenderTargets;
bool m_bInStubMode;
bool m_bGeneratedConfig;
bool m_bInFrame;
bool m_bForcedSingleThreaded;
bool m_bAllowQueuedRendering;
std::atomic_bool m_bThreadHasOwnership;
uint m_ThreadOwnershipID;
ThreadId_t m_ThreadOwnershipID;

//---------------------------------

Expand Down
2 changes: 1 addition & 1 deletion materialsystem/ctexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3980,7 +3980,7 @@ void CTexture::DeleteIfUnreferenced()
if ( ThreadInMainThread() )
{
// Render thread better not be active or bad things can happen.
Assert( MaterialSystem()->GetRenderThreadId() == 0xFFFFFFFF );
Assert( MaterialSystem()->GetRenderThreadId() == -1 );
TextureManager()->RemoveTexture( this );
return;
}
Expand Down
2 changes: 1 addition & 1 deletion materialsystem/imaterialsysteminternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ abstract_class IMaterialSystemInternal : public IMaterialSystem
virtual CMatCallQueue *GetRenderCallQueue() = 0;

virtual void UnbindMaterial( IMaterial *pMaterial ) = 0;
virtual uint GetRenderThreadId() const = 0 ;
virtual ThreadId_t GetRenderThreadId() const = 0 ;

virtual IMaterialProxy *DetermineProxyReplacements( IMaterial *pMaterial, KeyValues *pFallbackKeyValues ) = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion materialsystem/shaderapidx9/shaderdevicebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ void CShaderDeviceBase::SetCurrentThreadAsOwner()

void CShaderDeviceBase::RemoveThreadOwner()
{
m_dwThreadId = 0xFFFFFFFF;
m_dwThreadId = -1;
}

bool CShaderDeviceBase::ThreadOwnsDevice()
Expand Down
2 changes: 1 addition & 1 deletion materialsystem/shaderapidx9/shaderdevicebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class CShaderDeviceBase : public IShaderDevice

int m_nWindowWidth;
int m_nWindowHeight;
uint32 m_dwThreadId;
ThreadId_t m_dwThreadId;
};


Expand Down
12 changes: 6 additions & 6 deletions materialsystem/texturemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,8 @@ class CTextureManager : public ITextureManager
friend class AsyncReader;
AsyncReader* m_pAsyncReader;

uint m_nAsyncLoadThread;
uint m_nAsyncReadThread;
ThreadId_t m_nAsyncLoadThread;
ThreadId_t m_nAsyncReadThread;

int m_iSuspendTextureStreaming;
};
Expand Down Expand Up @@ -1097,7 +1097,7 @@ class TSLIST_HEAD_ALIGN AsyncLoader : public CAlignedNewDelete<TSLIST_HEAD_ALIGN

s_TextureManager.m_nAsyncLoadThread = ThreadGetCurrentId();
( ( AsyncLoader* )_this )->ThreadLoader_Main();
s_TextureManager.m_nAsyncLoadThread = 0xFFFFFFFF;
s_TextureManager.m_nAsyncLoadThread = -1;
return 0;
}

Expand Down Expand Up @@ -1397,7 +1397,7 @@ class TSLIST_HEAD_ALIGN AsyncReader : public CAlignedNewDelete<TSLIST_HEAD_ALIGN

s_TextureManager.m_nAsyncReadThread = ThreadGetCurrentId();
( ( AsyncReader* ) _this )->ThreadReader_Main();
s_TextureManager.m_nAsyncReadThread = 0xFFFFFFFF;
s_TextureManager.m_nAsyncReadThread = -1;
return 0;
}

Expand All @@ -1422,8 +1422,8 @@ CTextureManager::CTextureManager( void )
, m_TextureExcludes( true )
, m_PendingAsyncLoads( true )
, m_textureStreamingRequests( DefLessFunc( ITextureInternal* ) )
, m_nAsyncLoadThread( 0xFFFFFFFF )
, m_nAsyncReadThread( 0xFFFFFFFF )
, m_nAsyncLoadThread( -1 )
, m_nAsyncReadThread( -1 )
{
m_iNextTexID = 0;
m_nFlags = 0;
Expand Down
2 changes: 1 addition & 1 deletion public/gcsdk/jobmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class CJobMgr
friend void Job_RegisterJobType( const JobType_t *pJobType );

JobID_t m_unNextJobID;
uint m_unFrameFuncThreadID; // the thread is JobMgr is working in
ThreadId_t m_unFrameFuncThreadID; // the thread is JobMgr is working in
bool m_bProfiling;
bool m_bIsShuttingDown;
int m_cErrorsToReport;
Expand Down
34 changes: 17 additions & 17 deletions public/tier0/threadtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ PLATFORM_INTERFACE bool ReleaseThreadHandle( ThreadHandle_t );
//-----------------------------------------------------------------------------

PLATFORM_INTERFACE void ThreadSleep(unsigned duration = 0);
PLATFORM_INTERFACE uint ThreadGetCurrentId();
PLATFORM_INTERFACE ThreadId_t ThreadGetCurrentId();
PLATFORM_INTERFACE ThreadHandle_t ThreadGetCurrentHandle();
PLATFORM_INTERFACE int ThreadGetPriority( ThreadHandle_t hThread = nullptr );
PLATFORM_INTERFACE bool ThreadSetPriority( ThreadHandle_t hThread, int priority );
Expand Down Expand Up @@ -733,7 +733,7 @@ class PLATFORM_CLASS CThreadMutex

#ifdef THREAD_MUTEX_TRACING_SUPPORTED
// Debugging (always here to allow mixed debug/release builds w/o changing size)
uint m_currentOwnerID;
ThreadId_t m_currentOwnerID;
uint16 m_lockCount;
bool m_bTrace;
#endif
Expand Down Expand Up @@ -761,7 +761,7 @@ class CThreadFastMutex
}

private:
FORCEINLINE bool TryLockInline( const uint32 threadId )
FORCEINLINE bool TryLockInline( const ThreadId_t threadId )
{
if ( threadId != m_ownerID.GetRaw() && !m_ownerID.AssignIf( 0, threadId ) )
return false;
Expand All @@ -771,17 +771,17 @@ class CThreadFastMutex
return true;
}

bool TryLock( const uint32 threadId )
bool TryLock( const ThreadId_t threadId )
{
return TryLockInline( threadId );
}

// dimhotepus: This one is for old vphysics dll to work.
PLATFORM_CLASS void Lock( const uint32 threadId, unsigned nSpinSleepTime ) volatile
{
const_cast<CThreadFastMutex *>(this)->Lock(threadId, nSpinSleepTime);
const_cast<CThreadFastMutex *>(this)->Lock( (ThreadId_t)threadId, nSpinSleepTime);
}
PLATFORM_CLASS void Lock( const uint32 threadId, unsigned nSpinSleepTime );
PLATFORM_CLASS void Lock( const ThreadId_t threadId, unsigned nSpinSleepTime );

public:
bool TryLock()
Expand All @@ -801,7 +801,7 @@ class CThreadFastMutex
#endif
void Lock( unsigned int nSpinSleepTime = 0 )
{
const uint32 threadId = ThreadGetCurrentId();
const ThreadId_t threadId = ThreadGetCurrentId();

if ( !TryLockInline( threadId ) )
{
Expand Down Expand Up @@ -1257,13 +1257,13 @@ class ALIGN8 PLATFORM_CLASS CThreadSpinRWLock : public CAlignedNewDelete<8>
private:
struct LockInfo_t
{
uint32 m_writerId;
ThreadId_t m_writerId;
int m_nReaders;
};

bool AssignIf( const LockInfo_t &newValue, const LockInfo_t &comperand );
bool TryLockForWrite( const uint32 threadId );
void SpinLockForWrite( const uint32 threadId );
bool TryLockForWrite( const ThreadId_t threadId );
void SpinLockForWrite( const ThreadId_t threadId );

volatile LockInfo_t m_lockInfo;

Expand Down Expand Up @@ -1652,9 +1652,9 @@ extern "C"
inline void CThreadMutex::Lock()
{
#ifdef THREAD_MUTEX_TRACING_ENABLED
uint thisThreadID = ThreadGetCurrentId();
ThreadId_t thisThreadID = ThreadGetCurrentId();
if ( m_bTrace && m_currentOwnerID && ( m_currentOwnerID != thisThreadID ) )
Msg( "Thread %u about to wait for lock %p owned by %u\n", ThreadGetCurrentId(), (CRITICAL_SECTION *)&m_CriticalSection, m_currentOwnerID );
Msg( "Thread %lu about to wait for lock %p owned by %lu\n", ThreadGetCurrentId(), (CRITICAL_SECTION *)&m_CriticalSection, m_currentOwnerID );
#endif

VCRHook_EnterCriticalSection((CRITICAL_SECTION *)&m_CriticalSection);
Expand All @@ -1665,7 +1665,7 @@ inline void CThreadMutex::Lock()
// we now own it for the first time. Set owner information
m_currentOwnerID = thisThreadID;
if ( m_bTrace )
Msg( "Thread %u now owns lock %p\n", m_currentOwnerID, (CRITICAL_SECTION *)&m_CriticalSection );
Msg( "Thread %lu now owns lock %p\n", m_currentOwnerID, (CRITICAL_SECTION *)&m_CriticalSection );
}
m_lockCount++;
#endif
Expand All @@ -1681,7 +1681,7 @@ inline void CThreadMutex::Unlock()
if (m_lockCount == 0)
{
if ( m_bTrace )
Msg( "Thread %u releasing lock %p\n", m_currentOwnerID, (CRITICAL_SECTION *)&m_CriticalSection );
Msg( "Thread %lu releasing lock %p\n", m_currentOwnerID, (CRITICAL_SECTION *)&m_CriticalSection );
m_currentOwnerID = 0;
}
#endif
Expand All @@ -1695,7 +1695,7 @@ inline bool CThreadMutex::AssertOwnedByCurrentThread() const
#ifdef THREAD_MUTEX_TRACING_ENABLED
if (ThreadGetCurrentId() == m_currentOwnerID)
return true;
AssertMsg3( 0, "Expected thread %u as owner of lock %p, but %u owns", ThreadGetCurrentId(), (const CRITICAL_SECTION *)&m_CriticalSection, m_currentOwnerID );
AssertMsg3( 0, "Expected thread %lu as owner of lock %p, but %lu owns", ThreadGetCurrentId(), (const CRITICAL_SECTION *)&m_CriticalSection, m_currentOwnerID );
return false;
#else
return true;
Expand Down Expand Up @@ -1807,7 +1807,7 @@ inline bool CThreadSpinRWLock::AssignIf( const LockInfo_t &newValue, const LockI
return ThreadInterlockedAssignIf64( (volatile int64 *)&m_lockInfo, *((const int64 *)&newValue), *((const int64 *)&comperand) );
}

inline bool CThreadSpinRWLock::TryLockForWrite( const uint32 threadId )
inline bool CThreadSpinRWLock::TryLockForWrite( const ThreadId_t threadId )
{
// In order to grab a write lock, there can be no readers and no owners of the write lock
if ( m_lockInfo.m_nReaders > 0 || ( m_lockInfo.m_writerId && m_lockInfo.m_writerId != threadId ) )
Expand Down Expand Up @@ -1860,7 +1860,7 @@ inline bool CThreadSpinRWLock::TryLockForRead()

inline void CThreadSpinRWLock::LockForWrite()
{
const uint32 threadId = ThreadGetCurrentId();
const ThreadId_t threadId = ThreadGetCurrentId();

++m_nWriters;

Expand Down
6 changes: 3 additions & 3 deletions public/tier0/vprof.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ class DBG_CLASS CVProfile
void Start();
void Stop();

void SetTargetThreadId( unsigned id ) { m_TargetThreadId = id; }
unsigned GetTargetThreadId() const { return m_TargetThreadId; }
void SetTargetThreadId( ThreadId_t id ) { m_TargetThreadId = id; }
ThreadId_t GetTargetThreadId() const { return m_TargetThreadId; }
bool InTargetThread() const { return ( m_TargetThreadId == ThreadGetCurrentId() ); }

void EnterScope( const tchar *pszName, int detailLevel, const tchar *pBudgetGroupName, bool bAssertAccounted );
Expand Down Expand Up @@ -545,7 +545,7 @@ class DBG_CLASS CVProfile
tchar *m_CounterNames[MAXCOUNTERS];
int m_NumCounters;

unsigned m_TargetThreadId;
ThreadId_t m_TargetThreadId;

StreamOut_t m_pOutputStream;
};
Expand Down
2 changes: 1 addition & 1 deletion tier0/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "tier0/dbg.h"
#include "tier0/threadtools.h"

unsigned long Plat_GetCurrentThreadID()
ThreadId_t Plat_GetCurrentThreadID()
{
return ThreadGetCurrentId();
}
Expand Down
Loading

0 comments on commit ee09a8e

Please sign in to comment.