[pypy-commit] stmgc queue: - fix timespec_delay() to accept values of 'incr' larger than 1.0
arigo
noreply at buildbot.pypy.org
Thu Jun 18 11:36:30 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: queue
Changeset: r1857:7c61144ee23d
Date: 2015-06-18 11:36 +0200
http://bitbucket.org/pypy/stmgc/changeset/7c61144ee23d/
Log: - fix timespec_delay() to accept values of 'incr' larger than 1.0
- pthread_cond_timedwait() can return EINTR
diff --git a/c8/stm/sync.c b/c8/stm/sync.c
--- a/c8/stm/sync.c
+++ b/c8/stm/sync.c
@@ -115,12 +115,15 @@
t->tv_sec = tv.tv_sec;
t->tv_nsec = tv.tv_usec * 1000 + 999;
#endif
- /* assumes that "incr" is not too large, less than 1 second */
+
+ long integral_part = (long)incr;
+ t->tv_sec += integral_part;
+ incr -= integral_part;
+
long nsec = t->tv_nsec + (long)(incr * 1000000000.0);
- if (nsec >= 1000000000) {
+ while (nsec >= 1000000000) {
t->tv_sec += 1;
nsec -= 1000000000;
- assert(nsec < 1000000000);
}
t->tv_nsec = nsec;
}
@@ -131,15 +134,21 @@
stm_fatalerror("*** cond_wait/%d called!", (int)ctype);
#endif
+ retry:
assert(_has_mutex_here);
int err = pthread_cond_timedwait(&sync_ctl.cond[ctype],
&sync_ctl.global_mutex, pt);
- if (err == 0)
+ switch (err) {
+ case 0:
return true; /* success */
- if (LIKELY(err == ETIMEDOUT))
+ case ETIMEDOUT:
return false; /* timeout */
- stm_fatalerror("pthread_cond_timedwait/%d: %d", (int)ctype, err);
+ case EINTR:
+ goto retry;
+ default:
+ stm_fatalerror("pthread_cond_timedwait/%d: %d", (int)ctype, err);
+ }
}
static bool cond_wait_timeout(enum cond_type_e ctype, double delay)
More information about the pypy-commit
mailing list