1 #include <simgear/compiler.h>
3 #if defined(_MSC_VER) || defined(__MINGW32__)
12 #include "SGThread.hxx"
15 start_handler( void* arg )
17 SGThread* thr = static_cast<SGThread*>(arg);
23 SGThread::set_cancel( cancel_t mode )
28 pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, 0 );
31 pthread_setcanceltype( PTHREAD_CANCEL_DEFERRED, 0 );
32 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 );
34 case CANCEL_IMMEDIATE:
35 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, 0 );
36 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 );
46 int status = pthread_mutex_lock( &mutex );
51 assert( status == 0 );
55 #if defined(_MSC_VER) || defined(__MINGW32__)
56 int gettimeofday(struct timeval* tp, void* tzp) {
59 if(QueryPerformanceCounter(&t)) {
60 /* hardware supports a performance counter */
62 QueryPerformanceFrequency(&f);
63 tp->tv_sec = t.QuadPart/f.QuadPart;
64 tp->tv_usec = ((float)t.QuadPart/f.QuadPart*1000*1000)
65 - (tp->tv_sec*1000*1000);
67 /* hardware doesn't support a performance counter, so get the
68 time in a more traditional way. */
71 tp->tv_sec = t / 1000;
72 tp->tv_usec = t % 1000;
75 /* 0 indicates that the call succeeded. */
81 SGPthreadCond::wait( SGMutex& mutex, unsigned long ms )
84 ::gettimeofday( &now, 0 );
86 // Wait time is now + ms milliseconds
87 unsigned int sec = ms / 1000;
88 unsigned int nsec = (ms % 1000) * 1000;
89 struct timespec abstime;
90 abstime.tv_sec = now.tv_sec + sec;
91 abstime.tv_nsec = now.tv_usec*1000 + nsec;
93 int status = pthread_cond_timedwait( &cond, &mutex.mutex, &abstime );
94 if (status == ETIMEDOUT)
99 assert( status == 0 );