summaryrefslogtreecommitdiff
path: root/src/common/std_condition_variable.h
diff options
context:
space:
mode:
authorGravatar archshift2014-09-02 22:05:45 -0700
committerGravatar archshift2014-09-07 14:31:07 -0700
commit498d1a37f16d36b0c6341b074e5390a9194567a7 (patch)
treeadbf248d2b6d18e475f2d5390ff8ed7d37b6a877 /src/common/std_condition_variable.h
parentMerge pull request #88 from archshift/remove-atomic (diff)
downloadyuzu-498d1a37f16d36b0c6341b074e5390a9194567a7.tar.gz
yuzu-498d1a37f16d36b0c6341b074e5390a9194567a7.tar.xz
yuzu-498d1a37f16d36b0c6341b074e5390a9194567a7.zip
Removed common/std_xyz, instead using the std header
Diffstat (limited to 'src/common/std_condition_variable.h')
-rw-r--r--src/common/std_condition_variable.h168
1 files changed, 0 insertions, 168 deletions
diff --git a/src/common/std_condition_variable.h b/src/common/std_condition_variable.h
deleted file mode 100644
index ad2022f5a..000000000
--- a/src/common/std_condition_variable.h
+++ /dev/null
@@ -1,168 +0,0 @@
1
2#pragma once
3
4#define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z))
5#define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
6
7#ifndef __has_include
8#define __has_include(s) 0
9#endif
10
11#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__
12
13// GCC 4.4 provides <condition_variable>
14#include <condition_variable>
15
16#elif __has_include(<condition_variable>) && !ANDROID
17
18// clang and libc++ provide <condition_variable> on OSX. However, the version
19// of libc++ bundled with OSX 10.7 and 10.8 is buggy: it uses _ as a variable.
20//
21// We work around this issue by undefining and redefining _.
22
23#undef _
24#include <condition_variable>
25#define _(s) wxGetTranslation((s))
26
27#else
28
29// partial std::condition_variable implementation for win32/pthread
30
31#include "common/std_mutex.h"
32
33#if (_MSC_VER >= 1600) || (GCC_VERSION >= GCC_VER(4,3,0) && __GXX_EXPERIMENTAL_CXX0X__)
34#define USE_RVALUE_REFERENCES
35#endif
36
37#if defined(_WIN32) && defined(_M_X64)
38#define USE_CONDITION_VARIABLES
39#elif defined(_WIN32)
40#define USE_EVENTS
41#endif
42
43namespace std
44{
45
46class condition_variable
47{
48#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES)
49 typedef CONDITION_VARIABLE native_type;
50#elif defined(_WIN32)
51 typedef HANDLE native_type;
52#else
53 typedef pthread_cond_t native_type;
54#endif
55
56public:
57
58#ifdef USE_EVENTS
59 typedef native_type native_handle_type;
60#else
61 typedef native_type* native_handle_type;
62#endif
63
64 condition_variable()
65 {
66#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES)
67 InitializeConditionVariable(&m_handle);
68#elif defined(_WIN32)
69 m_handle = CreateEvent(NULL, false, false, NULL);
70#else
71 pthread_cond_init(&m_handle, NULL);
72#endif
73 }
74
75 ~condition_variable()
76 {
77#if defined(_WIN32) && !defined(USE_CONDITION_VARIABLES)
78 CloseHandle(m_handle);
79#elif !defined(_WIN32)
80 pthread_cond_destroy(&m_handle);
81#endif
82 }
83
84 condition_variable(const condition_variable&) /*= delete*/;
85 condition_variable& operator=(const condition_variable&) /*= delete*/;
86
87 void notify_one()
88 {
89#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES)
90 WakeConditionVariable(&m_handle);
91#elif defined(_WIN32)
92 SetEvent(m_handle);
93#else
94 pthread_cond_signal(&m_handle);
95#endif
96 }
97
98 void notify_all()
99 {
100#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES)
101 WakeAllConditionVariable(&m_handle);
102#elif defined(_WIN32)
103 // TODO: broken
104 SetEvent(m_handle);
105#else
106 pthread_cond_broadcast(&m_handle);
107#endif
108 }
109
110 void wait(unique_lock<mutex>& lock)
111 {
112#ifdef _WIN32
113 #ifdef USE_SRWLOCKS
114 SleepConditionVariableSRW(&m_handle, lock.mutex()->native_handle(), INFINITE, 0);
115 #elif defined(USE_CONDITION_VARIABLES)
116 SleepConditionVariableCS(&m_handle, lock.mutex()->native_handle(), INFINITE);
117 #else
118 // TODO: broken, the unlock and wait need to be atomic
119 lock.unlock();
120 WaitForSingleObject(m_handle, INFINITE);
121 lock.lock();
122 #endif
123#else
124 pthread_cond_wait(&m_handle, lock.mutex()->native_handle());
125#endif
126 }
127
128 template <class Predicate>
129 void wait(unique_lock<mutex>& lock, Predicate pred)
130 {
131 while (!pred())
132 wait(lock);
133 }
134
135 //template <class Clock, class Duration>
136 //cv_status wait_until(unique_lock<mutex>& lock,
137 // const chrono::time_point<Clock, Duration>& abs_time);
138
139 //template <class Clock, class Duration, class Predicate>
140 // bool wait_until(unique_lock<mutex>& lock,
141 // const chrono::time_point<Clock, Duration>& abs_time,
142 // Predicate pred);
143
144 //template <class Rep, class Period>
145 //cv_status wait_for(unique_lock<mutex>& lock,
146 // const chrono::duration<Rep, Period>& rel_time);
147
148 //template <class Rep, class Period, class Predicate>
149 // bool wait_for(unique_lock<mutex>& lock,
150 // const chrono::duration<Rep, Period>& rel_time,
151 // Predicate pred);
152
153 native_handle_type native_handle()
154 {
155#ifdef USE_EVENTS
156 return m_handle;
157#else
158 return &m_handle;
159#endif
160 }
161
162private:
163 native_type m_handle;
164};
165
166}
167
168#endif