From c2a3e1b9ceb7eb195f8b51d81b95ae57140dc534 Mon Sep 17 00:00:00 2001 From: Aidan Chalk <aidan.chalk@stfc.ac.uk> Date: Wed, 26 Apr 2017 13:10:39 +0100 Subject: [PATCH] Changed the use of rand to rand_r to hopefully improve performance and to be thread-safe --- src/qsched.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qsched.c b/src/qsched.c index f6ce8b2..ae99a6a 100644 --- a/src/qsched.c +++ b/src/qsched.c @@ -810,7 +810,8 @@ struct task *qsched_gettask ( struct qsched *s , int qid ) { int naq, k, tid, qids[ s->nr_queues ]; struct task *t; - + unsigned int seed = qid; + TIMER_TIC /* Check if the sched is ok. */ @@ -836,7 +837,7 @@ struct task *qsched_gettask ( struct qsched *s , int qid ) { if ( k != qid && s->queues[k].count > 0 ) qids[ naq++ ] = k; while ( naq > 0 ) { - k = rand() % naq; + k = rand_r(&seed) % naq; TIMER_TIC2 tid = queue_get( &s->queues[ qids[k] ] , s , 0 ); TIMER_TOC( s , qsched_timer_queue ) -- GitLab