X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fthreads%2FSGThread.cxx;h=c7a841b02bb9d8b0ddb3dadbf3621baca0812ca5;hb=6a7c2000027cd22eea603e936ddbad1a5bfc8b04;hp=27f560822610593df7c70dec98a5a5cb319d6c4c;hpb=0b316a8c5ee9c36f183c2ad0ef6686e2ed5f47c1;p=simgear.git diff --git a/simgear/threads/SGThread.cxx b/simgear/threads/SGThread.cxx index 27f56082..c7a841b0 100644 --- a/simgear/threads/SGThread.cxx +++ b/simgear/threads/SGThread.cxx @@ -1,9 +1,18 @@ -#ifdef HAVE_CONFIG_H -# include -#endif - #include -#include + +#if defined(_MSC_VER) || defined(__MINGW32__) +# include +#else +# if defined ( sgi ) && !defined( __GNUC__ ) + // This works around a bug triggered when using MipsPro 7.4.1 + // and (at least) IRIX 6.5.20 +# include +# endif +# include +#endif +#if _MSC_VER >= 1300 +# include +#endif #include "SGThread.hxx" @@ -15,6 +24,27 @@ start_handler( void* arg ) return 0; } +void +SGThread::set_cancel( cancel_t mode ) +{ + switch (mode) + { + case CANCEL_DISABLE: + pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, 0 ); + break; + case CANCEL_DEFERRED: + pthread_setcanceltype( PTHREAD_CANCEL_DEFERRED, 0 ); + pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 ); + break; + case CANCEL_IMMEDIATE: + pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, 0 ); + pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 ); + break; + default: + break; + } +} + bool SGMutex::trylock() { @@ -27,8 +57,33 @@ SGMutex::trylock() return true; } +#if defined(_MSC_VER) || defined(__MINGW32__) +int gettimeofday(struct timeval* tp, void* tzp) { + LARGE_INTEGER t; + + if(QueryPerformanceCounter(&t)) { + /* hardware supports a performance counter */ + LARGE_INTEGER f; + QueryPerformanceFrequency(&f); + tp->tv_sec = t.QuadPart/f.QuadPart; + tp->tv_usec = ((float)t.QuadPart/f.QuadPart*1000*1000) + - (tp->tv_sec*1000*1000); + } else { + /* hardware doesn't support a performance counter, so get the + time in a more traditional way. */ + DWORD t; + t = timeGetTime(); + tp->tv_sec = t / 1000; + tp->tv_usec = t % 1000; + } + + /* 0 indicates that the call succeeded. */ + return 0; +} +#endif + bool -SGCondition::wait( SGMutex& mutex, unsigned long ms ) +SGPthreadCond::wait( SGMutex& mutex, unsigned long ms ) { struct timeval now; ::gettimeofday( &now, 0 );