| 115 | */ |
| 116 | extern "C" |
| 117 | int |
| 118 | SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) |
| 119 | { |
| 120 | if (!cond) { |
| 121 | SDL_SetError("Passed a NULL condition variable"); |
| 122 | return -1; |
| 123 | } |
| 124 | |
| 125 | if (!mutex) { |
| 126 | SDL_SetError("Passed a NULL mutex variable"); |
| 127 | return -1; |
| 128 | } |
| 129 | |
| 130 | try { |
| 131 | std::unique_lock<std::recursive_mutex> cpp_lock(mutex->cpp_mutex, std::adopt_lock_t()); |
| 132 | if (ms == SDL_MUTEX_MAXWAIT) { |
| 133 | cond->cpp_cond.wait( |
| 134 | cpp_lock |
| 135 | ); |
| 136 | cpp_lock.release(); |
| 137 | return 0; |
| 138 | } else { |
| 139 | auto wait_result = cond->cpp_cond.wait_for( |
| 140 | cpp_lock, |
| 141 | std::chrono::duration<Uint32, std::milli>(ms) |
| 142 | ); |
| 143 | cpp_lock.release(); |
| 144 | if (wait_result == std::cv_status::timeout) { |
| 145 | return SDL_MUTEX_TIMEDOUT; |
| 146 | } else { |
| 147 | return 0; |
| 148 | } |
| 149 | } |
| 150 | } catch (std::system_error & ex) { |
| 151 | SDL_SetError("unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what()); |
| 152 | return -1; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /* Wait on the condition variable forever */ |
| 157 | extern "C" |
no test coverage detected