1 #include <simgear/compiler.h>
3 #if defined(_MSC_VER) || defined(__MINGW32__)
6 # if defined ( sgi ) && !defined( __GNUC__ )
7 // This works around a bug triggered when using MipsPro 7.4.1
8 // and (at least) IRIX 6.5.20
11 # include <sys/time.h>
14 # include <winsock2.h>
17 #include "SGThread.hxx"
20 start_handler( void* arg )
22 SGThread* thr = static_cast<SGThread*>(arg);
28 SGThread::set_cancel( cancel_t mode )
33 pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, 0 );
36 pthread_setcanceltype( PTHREAD_CANCEL_DEFERRED, 0 );
37 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 );
39 case CANCEL_IMMEDIATE:
40 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, 0 );
41 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 );
51 int status = pthread_mutex_lock( &mutex );
56 assert( status == 0 );
60 #if defined(_MSC_VER) || defined(__MINGW32__)
61 int gettimeofday(struct timeval* tp, void* tzp) {
64 if(QueryPerformanceCounter(&t)) {
65 /* hardware supports a performance counter */
67 QueryPerformanceFrequency(&f);
68 tp->tv_sec = t.QuadPart/f.QuadPart;
69 tp->tv_usec = ((float)t.QuadPart/f.QuadPart*1000*1000)
70 - (tp->tv_sec*1000*1000);
72 /* hardware doesn't support a performance counter, so get the
73 time in a more traditional way. */
76 tp->tv_sec = t / 1000;
77 tp->tv_usec = t % 1000;
80 /* 0 indicates that the call succeeded. */
86 SGPthreadCond::wait( SGMutex& mutex, unsigned long ms )
89 ::gettimeofday( &now, 0 );
91 // Wait time is now + ms milliseconds
92 unsigned int sec = ms / 1000;
93 unsigned int nsec = (ms % 1000) * 1000;
94 struct timespec abstime;
95 abstime.tv_sec = now.tv_sec + sec;
96 abstime.tv_nsec = now.tv_usec*1000 + nsec;
98 int status = pthread_cond_timedwait( &cond, &mutex.mutex, &abstime );
99 if (status == ETIMEDOUT)
104 assert( status == 0 );