Merge branch 'linux'

This commit is contained in:
Robert Beckebans 2012-12-14 11:51:57 +01:00
commit 7e29478f9e
4 changed files with 64 additions and 29 deletions

View file

@ -154,7 +154,9 @@ private:
pthread_mutex_t mutex; pthread_mutex_t mutex;
pthread_cond_t cond; pthread_cond_t cond;
bool signaled; bool signaled;
int signalCounter;
bool waiting; bool waiting;
bool manualReset;
idSysSignal( const idSysSignal& s ) {} idSysSignal( const idSysSignal& s ) {}
void operator=( const idSysSignal& s ) {} void operator=( const idSysSignal& s ) {}

View file

@ -155,37 +155,49 @@ void Sys_Yield()
idSysSignal::idSysSignal( bool manualReset ) idSysSignal::idSysSignal( bool manualReset )
{ {
#if 0
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
//pthread_mutexattr_init( &attr ); pthread_mutexattr_init( &attr );
pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK ); pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK );
pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_DEFAULT ); //pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_DEFAULT );
pthread_mutex_init( &mutex, &attr ); pthread_mutex_init( &mutex, &attr );
pthread_mutexattr_destroy( &attr ); pthread_mutexattr_destroy( &attr );
#else
pthread_mutex_init( &mutex, NULL );
#endif
pthread_cond_init( &cond, NULL ); pthread_cond_init( &cond, NULL );
signaled = false; signaled = false;
signalCounter = 0;
waiting = false; waiting = false;
this->manualReset = manualReset;
} }
idSysSignal::~idSysSignal() idSysSignal::~idSysSignal()
{ {
pthread_cond_destroy( &cond ); pthread_cond_destroy( &cond );
pthread_mutex_destroy( &mutex );
} }
void idSysSignal::Raise() void idSysSignal::Raise()
{ {
pthread_mutex_lock( &mutex ); pthread_mutex_lock( &mutex );
if( waiting ) //if( waiting )
{ {
pthread_cond_signal( &cond ); //pthread_cond_signal( &cond );
//pthread_cond_broadcast( &cond );
} }
else //else
if( !signaled )
{ {
// emulate Windows behaviour: if no thread is waiting, leave the signal on so next wait keeps going // emulate Windows behaviour: if no thread is waiting, leave the signal on so next wait keeps going
signaled = true; signaled = true;
signalCounter++;
pthread_cond_signal( &cond );
} }
pthread_mutex_unlock( &mutex ); pthread_mutex_unlock( &mutex );
@ -237,6 +249,7 @@ bool idSysSignal::Wait( int timeout )
The mutex was not owned by the current thread at the time of the call. The mutex was not owned by the current thread at the time of the call.
*/ */
#if 0
assert( !waiting ); // WaitForEvent from multiple threads? that wouldn't be good assert( !waiting ); // WaitForEvent from multiple threads? that wouldn't be good
if( signaled ) if( signaled )
{ {
@ -245,6 +258,9 @@ bool idSysSignal::Wait( int timeout )
result = 0; result = 0;
} }
else else
#endif
{
while( !signaled )
{ {
waiting = true; waiting = true;
#if 0 #if 0
@ -271,6 +287,12 @@ bool idSysSignal::Wait( int timeout )
waiting = false; waiting = false;
} }
if( !manualReset )
{
signaled = false;
}
}
pthread_mutex_unlock( &mutex ); pthread_mutex_unlock( &mutex );
return ( result == 0 ); return ( result == 0 );

View file

@ -86,7 +86,7 @@ bool AssertFailed( const char* file, int line, const char* expression )
#ifdef _WIN32 #ifdef _WIN32
if( IsDebuggerPresent() || com_assertOutOfDebugger.GetBool() ) if( IsDebuggerPresent() || com_assertOutOfDebugger.GetBool() )
#else #else
if( com_assertOutOfDebugger.GetBool() ) //if( com_assertOutOfDebugger.GetBool() )
#endif #endif
// RB end // RB end
{ {

View file

@ -247,6 +247,7 @@ Sys_Microseconds
*/ */
uint64 Sys_Microseconds() uint64 Sys_Microseconds()
{ {
#if 1
static uint64 ticksPerMicrosecondTimes1024 = 0; static uint64 ticksPerMicrosecondTimes1024 = 0;
if( ticksPerMicrosecondTimes1024 == 0 ) if( ticksPerMicrosecondTimes1024 == 0 )
@ -256,6 +257,16 @@ uint64 Sys_Microseconds()
} }
return ( ( uint64 )( ( int64 )Sys_GetClockTicks() << 10 ) ) / ticksPerMicrosecondTimes1024; return ( ( uint64 )( ( int64 )Sys_GetClockTicks() << 10 ) ) / ticksPerMicrosecondTimes1024;
#else
uint64 curtime;
struct timespec ts;
clock_gettime( CLOCK_MONOTONIC, &ts );
curtime = ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
return curtime;
#endif
} }
/* /*