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_cond_t cond;
bool signaled;
int signalCounter;
bool waiting;
bool manualReset;
idSysSignal( const idSysSignal& s ) {}
void operator=( const idSysSignal& s ) {}

View file

@ -155,37 +155,49 @@ void Sys_Yield()
idSysSignal::idSysSignal( bool manualReset )
{
#if 0
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_DEFAULT );
//pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_DEFAULT );
pthread_mutex_init( &mutex, &attr );
pthread_mutexattr_destroy( &attr );
#else
pthread_mutex_init( &mutex, NULL );
#endif
pthread_cond_init( &cond, NULL );
signaled = false;
signalCounter = 0;
waiting = false;
this->manualReset = manualReset;
}
idSysSignal::~idSysSignal()
{
pthread_cond_destroy( &cond );
pthread_mutex_destroy( &mutex );
}
void idSysSignal::Raise()
{
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
signaled = true;
signalCounter++;
pthread_cond_signal( &cond );
}
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.
*/
#if 0
assert( !waiting ); // WaitForEvent from multiple threads? that wouldn't be good
if( signaled )
{
@ -245,30 +258,39 @@ bool idSysSignal::Wait( int timeout )
result = 0;
}
else
{
waiting = true;
#if 0
result = pthread_cond_wait( &cond, &mutex );
#else
if( timeout == WAIT_INFINITE )
{
result = pthread_cond_wait( &cond, &mutex );
assert( result == 0 );
}
else
{
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
ts.tv_nsec += ( timeout * 1000000 );
result = pthread_cond_timedwait( &cond, &mutex, &ts );
assert( result == 0 || ( timeout != idSysSignal::WAIT_INFINITE && result == ETIMEDOUT ) );
}
#endif
waiting = false;
{
while( !signaled )
{
waiting = true;
#if 0
result = pthread_cond_wait( &cond, &mutex );
#else
if( timeout == WAIT_INFINITE )
{
result = pthread_cond_wait( &cond, &mutex );
assert( result == 0 );
}
else
{
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
ts.tv_nsec += ( timeout * 1000000 );
result = pthread_cond_timedwait( &cond, &mutex, &ts );
assert( result == 0 || ( timeout != idSysSignal::WAIT_INFINITE && result == ETIMEDOUT ) );
}
#endif
waiting = false;
}
if( !manualReset )
{
signaled = false;
}
}
pthread_mutex_unlock( &mutex );

View file

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

View file

@ -247,6 +247,7 @@ Sys_Microseconds
*/
uint64 Sys_Microseconds()
{
#if 1
static uint64 ticksPerMicrosecondTimes1024 = 0;
if( ticksPerMicrosecondTimes1024 == 0 )
@ -256,6 +257,16 @@ uint64 Sys_Microseconds()
}
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
}
/*