From: Andre Noll Date: Thu, 9 Jan 2014 17:04:28 +0000 (+0000) Subject: sched: Mark global now pointer as const. X-Git-Tag: v0.5.3~8^2~1 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=227a2ce5446c3f2ef4fd3e7c2ada3bb8d15289f1;hp=879e52d49df6d00aa9eafe5cccb48bbd24ed4c81 sched: Mark global now pointer as const. The timeval structure pointed to by the public now pointer should not be modified outside sched.c. Fortunately play.c is the only place which violates this rule. This patch fixes up play.c and marks the pointer as const. --- diff --git a/play.c b/play.c index cf7c5a30..c2a383c1 100644 --- a/play.c +++ b/play.c @@ -301,7 +301,7 @@ static int shuffle_compare(__a_unused const void *a, __a_unused const void *b) static void shuffle(char **base, size_t num) { - srandom(now->tv_sec); + srandom(time(NULL)); qsort(base, num, sizeof(char *), shuffle_compare); } @@ -1240,7 +1240,6 @@ int main(int argc, char *argv[]) filter_init(); writer_init(); - clock_get_realtime(now); sched.default_timeout.tv_sec = 5; parse_config_or_die(argc, argv); diff --git a/sched.c b/sched.c index f355c975..44062a66 100644 --- a/sched.c +++ b/sched.c @@ -49,7 +49,7 @@ struct task { }; static struct timeval now_struct; -struct timeval *now = &now_struct; +const struct timeval *now = &now_struct; static inline bool timeout_is_zero(struct sched *s) { @@ -147,7 +147,7 @@ again: FD_ZERO(&s->wfds); s->select_timeout = s->default_timeout; s->max_fileno = -1; - clock_get_realtime(now); + clock_get_realtime(&now_struct); sched_preselect(s); ret = s->select_function(s->max_fileno + 1, &s->rfds, &s->wfds, &s->select_timeout); @@ -163,7 +163,7 @@ again: FD_ZERO(&s->rfds); FD_ZERO(&s->wfds); } - clock_get_realtime(now); + clock_get_realtime(&now_struct); num_running_tasks = sched_post_select(s); if (num_running_tasks == 0) return 0; diff --git a/sched.h b/sched.h index 9c0e10a3..07877c46 100644 --- a/sched.h +++ b/sched.h @@ -68,7 +68,7 @@ struct task_info { * scheduler are allowed to block, this value should be accurate enough so that * there is no need to call clock_gettime() directly. */ -extern struct timeval *now; +extern const struct timeval *now; struct task *task_register(struct task_info *info, struct sched *s); int schedule(struct sched *s);