diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-09-18 11:02:37 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-09-18 11:02:37 -0400 |
commit | a23a168f24b490958e999603a719d15ae42755a9 (patch) | |
tree | 81959472e1ffd1bbbe3a548884cc99cf8155f5b0 /src | |
parent | aaf0fa6d1177c045a46ad1e5d6321396bf3690cd (diff) | |
parent | c7af923567bca5b0a6e9dcd5ceda4b01be09f9a1 (diff) | |
download | tor-a23a168f24b490958e999603a719d15ae42755a9.tar.gz tor-a23a168f24b490958e999603a719d15ae42755a9.zip |
Merge remote-tracking branch 'dgoulet/bug23558_032_01'
Diffstat (limited to 'src')
-rw-r--r-- | src/or/scheduler.c | 6 | ||||
-rw-r--r-- | src/or/scheduler_kist.c | 15 |
2 files changed, 17 insertions, 4 deletions
diff --git a/src/or/scheduler.c b/src/or/scheduler.c index 2d6f7fc4bd..43fff2bf2b 100644 --- a/src/or/scheduler.c +++ b/src/or/scheduler.c @@ -506,7 +506,11 @@ scheduler_ev_add(const struct timeval *next_run) { tor_assert(run_sched_ev); tor_assert(next_run); - event_add(run_sched_ev, next_run); + if (BUG(event_add(run_sched_ev, next_run) < 0)) { + log_warn(LD_SCHED, "Adding to libevent failed. Next run time was set to: " + "%ld.%06ld", next_run->tv_sec, next_run->tv_usec); + return; + } } /* Make the scheduler event active with the given flags. */ diff --git a/src/or/scheduler_kist.c b/src/or/scheduler_kist.c index ba8d416dba..e4ae071072 100644 --- a/src/or/scheduler_kist.c +++ b/src/or/scheduler_kist.c @@ -507,16 +507,25 @@ kist_scheduler_schedule(void) { struct monotime_t now; struct timeval next_run; - int32_t diff; + int64_t diff; if (!have_work()) { return; } monotime_get(&now); - diff = (int32_t) monotime_diff_msec(&scheduler_last_run, &now); + + /* If time is really monotonic, we can never have now being smaller than the + * last scheduler run. The scheduler_last_run at first is set to 0. */ + diff = monotime_diff_msec(&scheduler_last_run, &now); + IF_BUG_ONCE(diff < 0) { + diff = 0; + } if (diff < sched_run_interval) { next_run.tv_sec = 0; - /* 1000 for ms -> us */ + /* Takes 1000 ms -> us. This will always be valid because diff can NOT be + * negative and can NOT be smaller than sched_run_interval so values can + * only go from 1000 usec (diff set to interval - 1) to 100000 usec (diff + * set to 0) for the maximum allowed run interval (100ms). */ next_run.tv_usec = (sched_run_interval - diff) * 1000; /* Readding an event reschedules it. It does not duplicate it. */ scheduler_ev_add(&next_run); |