1 #include <simgear/compiler.h>
4 #include "SGThread.hxx"
7 start_handler( void* arg )
9 SGThread* thr = static_cast<SGThread*>(arg);
15 SGThread::set_cancel( cancel_t mode )
20 pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, 0 );
23 pthread_setcanceltype( PTHREAD_CANCEL_DEFERRED, 0 );
24 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 );
26 case CANCEL_IMMEDIATE:
27 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, 0 );
28 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0 );
38 int status = pthread_mutex_lock( &mutex );
43 assert( status == 0 );
48 SGCondition::wait( SGMutex& mutex, unsigned long ms )
51 ::gettimeofday( &now, 0 );
53 // Wait time is now + ms milliseconds
54 unsigned int sec = ms / 1000;
55 unsigned int nsec = (ms % 1000) * 1000;
56 struct timespec abstime;
57 abstime.tv_sec = now.tv_sec + sec;
58 abstime.tv_nsec = now.tv_usec*1000 + nsec;
60 int status = pthread_cond_timedwait( &cond, &mutex.mutex, &abstime );
61 if (status == ETIMEDOUT)
66 assert( status == 0 );