5 #include <simgear/compiler.h>
8 #include "SGThread.hxx"
11 start_handler( void* arg )
13 SGThread* thr = static_cast<SGThread*>(arg);
19 SGThread::set_cancel( cancel_t mode )
24 pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, 0 );
27 pthread_setcanceltype( PTHREAD_CANCEL_DEFERRED, 0 );
28 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 );
30 case CANCEL_IMMEDIATE:
31 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, 0 );
32 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 );
42 int status = pthread_mutex_lock( &mutex );
47 assert( status == 0 );
52 SGCondition::wait( SGMutex& mutex, unsigned long ms )
55 ::gettimeofday( &now, 0 );
57 // Wait time is now + ms milliseconds
58 unsigned int sec = ms / 1000;
59 unsigned int nsec = (ms % 1000) * 1000;
60 struct timespec abstime;
61 abstime.tv_sec = now.tv_sec + sec;
62 abstime.tv_nsec = now.tv_usec*1000 + nsec;
64 int status = pthread_cond_timedwait( &cond, &mutex.mutex, &abstime );
65 if (status == ETIMEDOUT)
70 assert( status == 0 );