9#ifndef MI_BASE_CONDITION_H
10#define MI_BASE_CONDITION_H
15#ifndef MI_PLATFORM_WINDOWS
20#include <mi/base/miwindows.h>
38#ifndef MI_PLATFORM_WINDOWS
40 pthread_mutex_init( &m_mutex, NULL);
41 pthread_cond_init( &m_condvar, NULL);
43 m_handle = CreateEvent( NULL,
false,
false, NULL);
50#ifndef MI_PLATFORM_WINDOWS
51 pthread_mutex_destroy( &m_mutex);
52 pthread_cond_destroy( &m_condvar);
54 CloseHandle( m_handle);
63#ifndef MI_PLATFORM_WINDOWS
64 pthread_mutex_lock( &m_mutex);
66 pthread_cond_wait( &m_condvar, &m_mutex);
68 pthread_mutex_unlock( &m_mutex);
70 WaitForSingleObject( m_handle, INFINITE);
82#ifndef MI_PLATFORM_WINDOWS
84 gettimeofday( &now, NULL);
85 struct timespec timeout_abs;
86 timeout_abs.tv_sec = now.tv_sec +
static_cast<long>( floor( timeout));
88 = 1000 * now.tv_usec +
static_cast<long>( 1E9 * ( timeout - floor( timeout)));
89 if( timeout_abs.tv_nsec > 1000000000) {
90 timeout_abs.tv_sec += 1;
91 timeout_abs.tv_nsec -= 1000000000;
94 bool timed_out =
false;
95 pthread_mutex_lock( &m_mutex);
98 int result = pthread_cond_timedwait( &m_condvar, &m_mutex, &timeout_abs);
99 timed_out = result == ETIMEDOUT;
104 pthread_mutex_unlock( &m_mutex);
107 DWORD timeout_ms =
static_cast<DWORD
>( 1000 * timeout);
108 DWORD result = WaitForSingleObject( m_handle, timeout_ms);
109 return result ==
WAIT_TIMEOUT;
123#ifndef MI_PLATFORM_WINDOWS
124 pthread_mutex_lock( &m_mutex);
126 pthread_cond_signal( &m_condvar);
127 pthread_mutex_unlock( &m_mutex);
138#ifndef MI_PLATFORM_WINDOWS
139 pthread_mutex_lock( &m_mutex);
141 pthread_mutex_unlock( &m_mutex);
143 ResetEvent( m_handle);
148#ifndef MI_PLATFORM_WINDOWS
150 pthread_mutex_t m_mutex;
152 pthread_cond_t m_condvar;
Conditions allow threads to signal an event and to wait for such a signal, respectively.
Definition: condition.h:33
Configuration of the Base API.
void reset()
Resets the condition.
Definition: condition.h:136
bool timed_wait(Float64 timeout)
Waits for the condition to be signaled until a given timeout.
Definition: condition.h:81
void signal()
Signals the condition.
Definition: condition.h:121
Condition()
Constructor.
Definition: condition.h:36
~Condition()
Destructor.
Definition: condition.h:48
void wait()
Waits for the condition to be signaled.
Definition: condition.h:61
double Float64
64-bit float.
Definition: types.h:52
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: base.h:34