aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/common/src/std_condition_variable.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/src/std_condition_variable.h')
-rw-r--r--src/common/src/std_condition_variable.h156
1 files changed, 78 insertions, 78 deletions
diff --git a/src/common/src/std_condition_variable.h b/src/common/src/std_condition_variable.h
index d44545e6..cee7a9dc 100644
--- a/src/common/src/std_condition_variable.h
+++ b/src/common/src/std_condition_variable.h
@@ -2,7 +2,7 @@
#ifndef CONDITION_VARIABLE_H_
#define CONDITION_VARIABLE_H_
-#define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z))
+#define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z))
#define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
#ifndef __has_include
@@ -47,121 +47,121 @@ namespace std
class condition_variable
{
#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES)
- typedef CONDITION_VARIABLE native_type;
+ typedef CONDITION_VARIABLE native_type;
#elif defined(_WIN32)
- typedef HANDLE native_type;
+ typedef HANDLE native_type;
#else
- typedef pthread_cond_t native_type;
+ typedef pthread_cond_t native_type;
#endif
public:
#ifdef USE_EVENTS
- typedef native_type native_handle_type;
+ typedef native_type native_handle_type;
#else
- typedef native_type* native_handle_type;
+ typedef native_type* native_handle_type;
#endif
- condition_variable()
- {
+ condition_variable()
+ {
#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES)
- InitializeConditionVariable(&m_handle);
+ InitializeConditionVariable(&m_handle);
#elif defined(_WIN32)
- m_handle = CreateEvent(NULL, false, false, NULL);
+ m_handle = CreateEvent(NULL, false, false, NULL);
#else
- pthread_cond_init(&m_handle, NULL);
+ pthread_cond_init(&m_handle, NULL);
#endif
- }
+ }
- ~condition_variable()
- {
+ ~condition_variable()
+ {
#if defined(_WIN32) && !defined(USE_CONDITION_VARIABLES)
- CloseHandle(m_handle);
+ CloseHandle(m_handle);
#elif !defined(_WIN32)
- pthread_cond_destroy(&m_handle);
+ pthread_cond_destroy(&m_handle);
#endif
- }
+ }
- condition_variable(const condition_variable&) /*= delete*/;
- condition_variable& operator=(const condition_variable&) /*= delete*/;
+ condition_variable(const condition_variable&) /*= delete*/;
+ condition_variable& operator=(const condition_variable&) /*= delete*/;
- void notify_one()
- {
+ void notify_one()
+ {
#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES)
- WakeConditionVariable(&m_handle);
+ WakeConditionVariable(&m_handle);
#elif defined(_WIN32)
- SetEvent(m_handle);
+ SetEvent(m_handle);
#else
- pthread_cond_signal(&m_handle);
+ pthread_cond_signal(&m_handle);
#endif
- }
+ }
- void notify_all()
- {
+ void notify_all()
+ {
#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES)
- WakeAllConditionVariable(&m_handle);
+ WakeAllConditionVariable(&m_handle);
#elif defined(_WIN32)
- // TODO: broken
- SetEvent(m_handle);
+ // TODO: broken
+ SetEvent(m_handle);
#else
- pthread_cond_broadcast(&m_handle);
+ pthread_cond_broadcast(&m_handle);
#endif
- }
+ }
- void wait(unique_lock<mutex>& lock)
- {
+ void wait(unique_lock<mutex>& lock)
+ {
#ifdef _WIN32
- #ifdef USE_SRWLOCKS
- SleepConditionVariableSRW(&m_handle, lock.mutex()->native_handle(), INFINITE, 0);
- #elif defined(USE_CONDITION_VARIABLES)
- SleepConditionVariableCS(&m_handle, lock.mutex()->native_handle(), INFINITE);
- #else
- // TODO: broken, the unlock and wait need to be atomic
- lock.unlock();
- WaitForSingleObject(m_handle, INFINITE);
- lock.lock();
- #endif
+ #ifdef USE_SRWLOCKS
+ SleepConditionVariableSRW(&m_handle, lock.mutex()->native_handle(), INFINITE, 0);
+ #elif defined(USE_CONDITION_VARIABLES)
+ SleepConditionVariableCS(&m_handle, lock.mutex()->native_handle(), INFINITE);
+ #else
+ // TODO: broken, the unlock and wait need to be atomic
+ lock.unlock();
+ WaitForSingleObject(m_handle, INFINITE);
+ lock.lock();
+ #endif
#else
- pthread_cond_wait(&m_handle, lock.mutex()->native_handle());
+ pthread_cond_wait(&m_handle, lock.mutex()->native_handle());
#endif
- }
-
- template <class Predicate>
- void wait(unique_lock<mutex>& lock, Predicate pred)
- {
- while (!pred())
- wait(lock);
- }
-
- //template <class Clock, class Duration>
- //cv_status wait_until(unique_lock<mutex>& lock,
- // const chrono::time_point<Clock, Duration>& abs_time);
-
- //template <class Clock, class Duration, class Predicate>
- // bool wait_until(unique_lock<mutex>& lock,
- // const chrono::time_point<Clock, Duration>& abs_time,
- // Predicate pred);
-
- //template <class Rep, class Period>
- //cv_status wait_for(unique_lock<mutex>& lock,
- // const chrono::duration<Rep, Period>& rel_time);
-
- //template <class Rep, class Period, class Predicate>
- // bool wait_for(unique_lock<mutex>& lock,
- // const chrono::duration<Rep, Period>& rel_time,
- // Predicate pred);
-
- native_handle_type native_handle()
- {
+ }
+
+ template <class Predicate>
+ void wait(unique_lock<mutex>& lock, Predicate pred)
+ {
+ while (!pred())
+ wait(lock);
+ }
+
+ //template <class Clock, class Duration>
+ //cv_status wait_until(unique_lock<mutex>& lock,
+ // const chrono::time_point<Clock, Duration>& abs_time);
+
+ //template <class Clock, class Duration, class Predicate>
+ // bool wait_until(unique_lock<mutex>& lock,
+ // const chrono::time_point<Clock, Duration>& abs_time,
+ // Predicate pred);
+
+ //template <class Rep, class Period>
+ //cv_status wait_for(unique_lock<mutex>& lock,
+ // const chrono::duration<Rep, Period>& rel_time);
+
+ //template <class Rep, class Period, class Predicate>
+ // bool wait_for(unique_lock<mutex>& lock,
+ // const chrono::duration<Rep, Period>& rel_time,
+ // Predicate pred);
+
+ native_handle_type native_handle()
+ {
#ifdef USE_EVENTS
- return m_handle;
+ return m_handle;
#else
- return &m_handle;
+ return &m_handle;
#endif
- }
+ }
private:
- native_type m_handle;
+ native_type m_handle;
};
}