MCPcopy Create free account
hub / github.com/SoarGroup/Soar / WaitForEvent

Method WaitForEvent

Core/ConnectionSML/src/thread_OSspecific.cpp:198–230  ·  view source on GitHub ↗

The timeout is seconds + milliseconds, where milliseconds < 1000

Source from the content-addressed store, hash-verified

196
197 //The timeout is seconds + milliseconds, where milliseconds < 1000
198 bool WaitForEvent(int sec, int milli) {
199 assert(milli < 1000 && "Specified milliseconds too large; use seconds argument to specify part of time >= 1000 milliseconds");
200 //return false;
201 pthread_mutex_lock(&m_mutex);
202
203 struct timeval now;
204 if (gettimeofday(&now, 0) != 0) {
205 // can't get time!?
206 pthread_mutex_unlock(&m_mutex);
207 return false;
208 }
209
210 struct timespec timeout;
211 timeout.tv_sec = now.tv_sec + sec;
212 timeout.tv_nsec = now.tv_usec * 1000L;
213 timeout.tv_nsec += (long)milli * 1000000L;
214
215 // make sure the nanoseconds field doesn't exceed 1 second (this is an error on OS X)
216 if(timeout.tv_nsec >= 1000000000L) {
217 timeout.tv_nsec -= 1000000000L;
218 timeout.tv_sec++;
219 }
220
221 while (!m_signaled) {
222 if (pthread_cond_timedwait(&m_cond, &m_mutex, &timeout) == ETIMEDOUT) {
223 pthread_mutex_unlock(&m_mutex);
224 return false;
225 }
226 }
227 m_signaled = false;
228 pthread_mutex_unlock(&m_mutex);
229 return true;
230 }
231 void TriggerEvent() {
232 pthread_mutex_lock(&m_mutex);
233 m_signaled = true;

Callers 5

destroySoarMethod · 0.45
WaitForEventFunction · 0.45
WaitForEventFunction · 0.45
GetResponseForIDMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected