mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
thread.c (timeout_prepare): common function
I can't seem to reproduce the maybe-uninitialized warning on gcc 7 or 8 on Debian sid (7.3.0-16 / 8-20180425-1 r259628), so the guard from r62305 is dropped. * thread.c (timeout_prepare): hoist out from do_select (do_select): ditto (rb_wait_for_single_fd): use timeout_prepare git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
cb2a2c2737
commit
986f11e72f
41
thread.c
41
thread.c
@ -242,6 +242,21 @@ timeval_for(struct timeval *tv, const struct timespec *ts)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
timeout_prepare(struct timespec **tsp,
|
||||
struct timespec *ts, struct timespec *end,
|
||||
const struct timeval *timeout)
|
||||
{
|
||||
if (timeout) {
|
||||
getclockofday(end);
|
||||
timespec_add(end, timespec_for(ts, timeout));
|
||||
*tsp = ts;
|
||||
}
|
||||
else {
|
||||
*tsp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if THREAD_DEBUG
|
||||
#ifdef HAVE_VA_ARGS_MACRO
|
||||
void rb_thread_debug(const char *file, int line, const char *fmt, ...);
|
||||
@ -3830,27 +3845,16 @@ do_select(int n, rb_fdset_t *const readfds, rb_fdset_t *const writefds,
|
||||
rb_fdset_t MAYBE_UNUSED(orig_read);
|
||||
rb_fdset_t MAYBE_UNUSED(orig_write);
|
||||
rb_fdset_t MAYBE_UNUSED(orig_except);
|
||||
struct timespec end;
|
||||
struct timespec *tsp = 0;
|
||||
struct timespec ts
|
||||
#if defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8)
|
||||
= {0, 0}
|
||||
#endif
|
||||
;
|
||||
struct timespec ts, end, *tsp;
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
|
||||
timeout_prepare(&tsp, &ts, &end, timeout);
|
||||
#define do_select_update() \
|
||||
(restore_fdset(readfds, &orig_read), \
|
||||
restore_fdset(writefds, &orig_write), \
|
||||
restore_fdset(exceptfds, &orig_except), \
|
||||
TRUE)
|
||||
|
||||
if (timeout) {
|
||||
getclockofday(&end);
|
||||
timespec_add(&end, timespec_for(&ts, timeout));
|
||||
tsp = &ts;
|
||||
}
|
||||
|
||||
#define fd_init_copy(f) \
|
||||
(f##fds) ? rb_fd_init_copy(&orig_##f, f##fds) : rb_fd_no_init(&orig_##f)
|
||||
fd_init_copy(read);
|
||||
@ -3988,17 +3992,10 @@ rb_wait_for_single_fd(int fd, int events, struct timeval *timeout)
|
||||
{
|
||||
struct pollfd fds;
|
||||
int result = 0, lerrno;
|
||||
struct timespec ts;
|
||||
struct timespec end;
|
||||
struct timespec *tsp = 0;
|
||||
struct timespec ts, end, *tsp;
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
|
||||
if (timeout) {
|
||||
getclockofday(&end);
|
||||
timespec_add(&end, timespec_for(&ts, timeout));
|
||||
tsp = &ts;
|
||||
}
|
||||
|
||||
timeout_prepare(&tsp, &ts, &end, timeout);
|
||||
fds.fd = fd;
|
||||
fds.events = (short)events;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user