MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / SDL_CondWaitTimeout

Function SDL_CondWaitTimeout

deps/SDL2/src/thread/stdcpp/SDL_syscond.cpp:117–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115 */
116extern "C"
117int
118SDL_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 */
157extern "C"

Callers 1

SDL_CondWaitFunction · 0.70

Calls 4

SDL_SetErrorFunction · 0.85
waitMethod · 0.45
releaseMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected