MCPcopy Create free account
hub / github.com/davisking/dlib / wait_or_timeout

Method wait_or_timeout

dlib/threads/threads_kernel_2.h:108–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106 }
107
108 bool wait_or_timeout (
109 unsigned long milliseconds
110 ) const
111 {
112 timespec time_to_wait;
113
114 timeval curtime;
115 gettimeofday(&curtime,0);
116
117 // get the time and adjust the timespec object by the appropriate amount
118 time_to_wait.tv_sec = milliseconds/1000 + curtime.tv_sec;
119 time_to_wait.tv_nsec = curtime.tv_usec;
120 time_to_wait.tv_nsec *= 1000;
121 time_to_wait.tv_nsec += (milliseconds%1000)*1000000;
122
123 time_to_wait.tv_sec += time_to_wait.tv_nsec/1000000000;
124 time_to_wait.tv_nsec = time_to_wait.tv_nsec%1000000000;
125
126 if ( pthread_cond_timedwait(&cond,associated_mutex,&time_to_wait) == ETIMEDOUT)
127 {
128 return false;
129 }
130 else
131 {
132 return true;
133 }
134 }
135
136 void signal (
137 ) const { pthread_cond_signal(&cond); }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected