mirror of
https://github.com/nillerusr/source-engine.git
synced 2024-12-22 14:16:50 +00:00
restore threadtools and vstdlib from 12716fd
commit
This commit is contained in:
parent
e4f5549cbd
commit
2aa14bb24c
@ -52,6 +52,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:4251)
|
#pragma warning(disable:4251)
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
void __declspec(dllimport) __stdcall Sleep( unsigned long );
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef COMPILER_MSVC64
|
#ifdef COMPILER_MSVC64
|
||||||
@ -194,8 +200,6 @@ PLATFORM_INTERFACE bool ReleaseThreadHandle( ThreadHandle_t );
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
PLATFORM_INTERFACE void ThreadSleep(unsigned duration = 0);
|
|
||||||
PLATFORM_INTERFACE void ThreadNanoSleep(unsigned ns);
|
|
||||||
PLATFORM_INTERFACE ThreadId_t ThreadGetCurrentId();
|
PLATFORM_INTERFACE ThreadId_t ThreadGetCurrentId();
|
||||||
PLATFORM_INTERFACE ThreadHandle_t ThreadGetCurrentHandle();
|
PLATFORM_INTERFACE ThreadHandle_t ThreadGetCurrentHandle();
|
||||||
PLATFORM_INTERFACE int ThreadGetPriority( ThreadHandle_t hThread = NULL );
|
PLATFORM_INTERFACE int ThreadGetPriority( ThreadHandle_t hThread = NULL );
|
||||||
@ -229,10 +233,10 @@ inline void ThreadPause()
|
|||||||
{
|
{
|
||||||
#if defined( COMPILER_PS3 )
|
#if defined( COMPILER_PS3 )
|
||||||
__db16cyc();
|
__db16cyc();
|
||||||
#elif defined(__arm__) || defined(__aarch64__)
|
#elif defined( COMPILER_GCC ) && (defined( __i386__ ) || defined( __x86_64__ ))
|
||||||
sched_yield();
|
|
||||||
#elif defined( COMPILER_GCC )
|
|
||||||
__asm __volatile( "pause" );
|
__asm __volatile( "pause" );
|
||||||
|
#elif defined( POSIX )
|
||||||
|
sched_yield();
|
||||||
#elif defined ( COMPILER_MSVC64 )
|
#elif defined ( COMPILER_MSVC64 )
|
||||||
_mm_pause();
|
_mm_pause();
|
||||||
#elif defined( COMPILER_MSVC32 )
|
#elif defined( COMPILER_MSVC32 )
|
||||||
@ -247,6 +251,36 @@ inline void ThreadPause()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void ThreadSleep(unsigned nMilliseconds = 0)
|
||||||
|
{
|
||||||
|
if( nMilliseconds == 0 )
|
||||||
|
{
|
||||||
|
ThreadPause();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#ifdef _WIN32_PC
|
||||||
|
static bool bInitialized = false;
|
||||||
|
if ( !bInitialized )
|
||||||
|
{
|
||||||
|
bInitialized = true;
|
||||||
|
// Set the timer resolution to 1 ms (default is 10.0, 15.6, 2.5, 1.0 or
|
||||||
|
// some other value depending on hardware and software) so that we can
|
||||||
|
// use Sleep( 1 ) to avoid wasting CPU time without missing our frame
|
||||||
|
// rate.
|
||||||
|
timeBeginPeriod( 1 );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Sleep( nMilliseconds );
|
||||||
|
#elif PS3
|
||||||
|
sys_timer_usleep( nMilliseconds * 1000 );
|
||||||
|
#elif defined(POSIX)
|
||||||
|
usleep( nMilliseconds * 1000 );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
PLATFORM_INTERFACE bool ThreadJoin( ThreadHandle_t, unsigned timeout = TT_INFINITE );
|
PLATFORM_INTERFACE bool ThreadJoin( ThreadHandle_t, unsigned timeout = TT_INFINITE );
|
||||||
|
|
||||||
PLATFORM_INTERFACE void ThreadSetDebugName( ThreadHandle_t hThread, const char *pszName );
|
PLATFORM_INTERFACE void ThreadSetDebugName( ThreadHandle_t hThread, const char *pszName );
|
||||||
|
@ -485,59 +485,6 @@ bool ReleaseThreadHandle( ThreadHandle_t hThread )
|
|||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void ThreadSleep(unsigned nMilliseconds)
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
#ifdef _WIN32_PC
|
|
||||||
static bool bInitialized = false;
|
|
||||||
if ( !bInitialized )
|
|
||||||
{
|
|
||||||
bInitialized = true;
|
|
||||||
// Set the timer resolution to 1 ms (default is 10.0, 15.6, 2.5, 1.0 or
|
|
||||||
// some other value depending on hardware and software) so that we can
|
|
||||||
// use Sleep( 1 ) to avoid wasting CPU time without missing our frame
|
|
||||||
// rate.
|
|
||||||
timeBeginPeriod( 1 );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Sleep( nMilliseconds );
|
|
||||||
#elif PS3
|
|
||||||
if( nMilliseconds == 0 )
|
|
||||||
{
|
|
||||||
// sys_ppu_thread_yield doesn't seem to function properly, so sleep instead.
|
|
||||||
// sys_timer_usleep( 60 );
|
|
||||||
sys_ppu_thread_yield();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sys_timer_usleep( nMilliseconds * 1000 );
|
|
||||||
}
|
|
||||||
#elif defined(POSIX)
|
|
||||||
usleep( nMilliseconds * 1000 );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
void ThreadNanoSleep(unsigned ns)
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
// ceil
|
|
||||||
Sleep( ( ns + 999 ) / 1000 );
|
|
||||||
#elif PS3
|
|
||||||
sys_timer_usleep( ns );
|
|
||||||
#elif defined(POSIX)
|
|
||||||
struct timespec tm;
|
|
||||||
tm.tv_sec = 0;
|
|
||||||
tm.tv_nsec = ns;
|
|
||||||
nanosleep( &tm, NULL );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef ThreadGetCurrentId
|
#ifndef ThreadGetCurrentId
|
||||||
ThreadId_t ThreadGetCurrentId()
|
ThreadId_t ThreadGetCurrentId()
|
||||||
{
|
{
|
||||||
|
@ -214,7 +214,11 @@ public:
|
|||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
virtual int YieldWait( CThreadEvent **pEvents, int nEvents, bool bWaitAll = true, unsigned timeout = TT_INFINITE );
|
virtual int YieldWait( CThreadEvent **pEvents, int nEvents, bool bWaitAll = true, unsigned timeout = TT_INFINITE );
|
||||||
virtual int YieldWait( CJob **, int nJobs, bool bWaitAll = true, unsigned timeout = TT_INFINITE );
|
virtual int YieldWait( CJob **, int nJobs, bool bWaitAll = true, unsigned timeout = TT_INFINITE );
|
||||||
void Yield( unsigned timeout );
|
inline void Yield( unsigned timeout )
|
||||||
|
{
|
||||||
|
Assert( ThreadInMainThread() );
|
||||||
|
ThreadSleep( timeout );
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
// Add a native job to the queue (master thread)
|
// Add a native job to the queue (master thread)
|
||||||
@ -656,20 +660,6 @@ int CThreadPool::YieldWait( CJob **ppJobs, int nJobs, bool bWaitAll, unsigned ti
|
|||||||
return YieldWait( handles.Base(), handles.Count(), bWaitAll, timeout);
|
return YieldWait( handles.Base(), handles.Count(), bWaitAll, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------
|
|
||||||
|
|
||||||
void CThreadPool::Yield( unsigned timeout )
|
|
||||||
{
|
|
||||||
// @MULTICORE (toml 10/24/2006): not implemented
|
|
||||||
Assert( ThreadInMainThread() );
|
|
||||||
if ( !ThreadInMainThread() )
|
|
||||||
{
|
|
||||||
ThreadSleep( timeout );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ThreadSleep( timeout );
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------
|
//---------------------------------------------------------
|
||||||
// Add a job to the queue
|
// Add a job to the queue
|
||||||
//---------------------------------------------------------
|
//---------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user