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 );
53 SGCondition::wait( SGMutex& mutex, unsigned long ms )
56 ::gettimeofday( &now, 0 );
58 // Wait time is now + ms milliseconds
59 unsigned int sec = ms / 1000;
60 unsigned int nsec = (ms % 1000) * 1000;
61 struct timespec abstime;
62 abstime.tv_sec = now.tv_sec + sec;
63 abstime.tv_nsec = now.tv_usec*1000 + nsec;
65 int status = pthread_cond_timedwait( &cond, &mutex.mutex, &abstime );
66 if (status == ETIMEDOUT)
71 assert( status == 0 );