1 #include <simgear/compiler.h>
3 #if defined(_MSC_VER) || defined(__MINGW32__)
9 #include "SGThread.hxx"
12 start_handler( void* arg )
14 SGThread* thr = static_cast<SGThread*>(arg);
20 SGThread::set_cancel( cancel_t mode )
25 pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, 0 );
28 pthread_setcanceltype( PTHREAD_CANCEL_DEFERRED, 0 );
29 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 );
31 case CANCEL_IMMEDIATE:
32 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, 0 );
33 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 );
43 int status = pthread_mutex_lock( &mutex );
48 assert( status == 0 );
52 #if defined(_MSC_VER) || defined(__MINGW32__)
53 int gettimeofday(struct timeval* tp, void* tzp) {
56 if(QueryPerformanceCounter(&t)) {
57 /* hardware supports a performance counter */
59 QueryPerformanceFrequency(&f);
60 tp->tv_sec = t.QuadPart/f.QuadPart;
61 tp->tv_usec = ((float)t.QuadPart/f.QuadPart*1000*1000)
62 - (tp->tv_sec*1000*1000);
64 /* hardware doesn't support a performance counter, so get the
65 time in a more traditional way. */
68 tp->tv_sec = t / 1000;
69 tp->tv_usec = t % 1000;
72 /* 0 indicates that the call succeeded. */
78 SGPthreadCond::wait( SGMutex& mutex, unsigned long ms )
81 ::gettimeofday( &now, 0 );
83 // Wait time is now + ms milliseconds
84 unsigned int sec = ms / 1000;
85 unsigned int nsec = (ms % 1000) * 1000;
86 struct timespec abstime;
87 abstime.tv_sec = now.tv_sec + sec;
88 abstime.tv_nsec = now.tv_usec*1000 + nsec;
90 int status = pthread_cond_timedwait( &cond, &mutex.mutex, &abstime );
91 if (status == ETIMEDOUT)
96 assert( status == 0 );