comparison libfdproto/sessions.c @ 1376:b8afaf63f65a

Handle case where pthread_cond_timedwait returns EINVAL if abstime has passed before it was called.
author Thomas Klausner <tk@giga.or.at>
date Thu, 20 Jun 2019 11:33:29 +0200
parents a4dd31276f17
children 566bb46cc73f
comparison
equal deleted inserted replaced
1375:2bd83cd4d2b2 1376:b8afaf63f65a
204 /* Get the current time */ 204 /* Get the current time */
205 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), break ); 205 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), break );
206 206
207 /* If first session is not expired, we just wait until it happens */ 207 /* If first session is not expired, we just wait until it happens */
208 if ( TS_IS_INFERIOR( &now, &first->timeout ) ) { 208 if ( TS_IS_INFERIOR( &now, &first->timeout ) ) {
209 CHECK_POSIX_DO2( pthread_cond_timedwait( &exp_cond, &exp_lock, &first->timeout ), 209 int ret;
210 ETIMEDOUT, /* ETIMEDOUT is a normal error, continue */, 210
211 /* on other error, */ break ); 211 ret = pthread_cond_timedwait(&exp_cond, &exp_lock, &first->timeout);
212 212 switch (ret) {
213 /* on wakeup, loop */ 213 case 0:
214 goto again; 214 case ETIMEDOUT:
215 /* on wakeup or time-out, loop */
216 goto again;
217 case EINVAL:
218 if (clock_gettime(CLOCK_REALTIME, &now) < 0) {
219 break;
220 }
221 if (TS_IS_INFERIOR(&now, &first->timeout)) {
222 TRACE_DEBUG(FULL, "'pthread_cond_timedwait(&exp_cond, &exp_lock, &first->timeout)' : timer expired before loop could start");
223 goto again;
224 }
225 /* FALLTHROUGH */
226 default:
227 TRACE_ERROR("ERROR: in 'pthread_cond_timedwait(&exp_cond, &exp_lock, &first->timeout)' :\t%s", strerror(ret));
228 break;
229 }
215 } 230 }
216 231
217 /* Now, the first session in the list is expired; destroy it */ 232 /* Now, the first session in the list is expired; destroy it */
218 pthread_cleanup_pop( 0 ); 233 pthread_cleanup_pop( 0 );
219 CHECK_POSIX_DO( pthread_mutex_unlock(&exp_lock), break ); 234 CHECK_POSIX_DO( pthread_mutex_unlock(&exp_lock), break );
"Welcome to our mercurial repository"