25 void XMutex::lock() {m_mutex.lock();}
27 void XMutex::unlock() {m_mutex.unlock();}
31 XCondition::XCondition() :
XMutex() {
33 XCondition::~XCondition() {
39 ret = m_cond.wait( &m_mutex, usec / 1000);
41 ret = m_cond.wait( &m_mutex);
63 pthread_mutexattr_t attr;
65 ret = pthread_mutexattr_init( &attr);
66 if(DEBUG_XTHREAD) assert( !ret);
68 ret = pthread_mutex_init( &m_mutex, &attr);
69 if(DEBUG_XTHREAD) assert( !ret);
71 ret = pthread_mutexattr_destroy( &attr);
72 if(DEBUG_XTHREAD) assert( !ret);
76 int ret = pthread_mutex_destroy( &m_mutex);
77 if(DEBUG_XTHREAD) assert( !ret);
81 int ret = pthread_mutex_lock( &m_mutex);
82 if(DEBUG_XTHREAD) assert( !ret);
86 int ret = pthread_mutex_trylock(&m_mutex);
87 if(DEBUG_XTHREAD) assert(ret != EINVAL);
92 int ret = pthread_mutex_unlock( &m_mutex);
93 if(DEBUG_XTHREAD) assert( !ret);
96 XCondition::XCondition() :
XMutex() {
97 int ret = pthread_cond_init( &m_cond, NULL);
98 if(DEBUG_XTHREAD) assert( !ret);
100 XCondition::~XCondition() {
101 int ret = pthread_cond_destroy( &m_cond);
102 if(DEBUG_XTHREAD) assert( !ret);
108 struct timespec abstime;
111 gettimeofday(&tv, NULL);
112 abstime.tv_sec = tv.tv_sec;
113 nsec = (tv.tv_usec + usec) * 1000;
114 if(nsec >= 1000000000) {
115 nsec -= 1000000000; abstime.tv_sec++;
117 abstime.tv_nsec = nsec;
118 ret = pthread_cond_timedwait(&m_cond, &m_mutex, &abstime);
121 ret = pthread_cond_wait(&m_cond, &m_mutex);
127 int ret = pthread_cond_signal( &m_cond);
128 if(DEBUG_XTHREAD) assert( !ret);
132 int ret = pthread_cond_broadcast( &m_cond);
133 if(DEBUG_XTHREAD) assert( !ret);
135 #endif // USE_PTHREAD
136 #endif // USE_QTHREAD