From 9a76d718c709da7d69d3533e1b2019a768343af5 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Thu, 14 Feb 2013 01:18:16 -0800 Subject: [PATCH] don't deplete RNG entropy when there is only one runnable task --- src/rt/rust_sched_loop.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rt/rust_sched_loop.cpp b/src/rt/rust_sched_loop.cpp index 01c377356a3..7143bf88d46 100644 --- a/src/rt/rust_sched_loop.cpp +++ b/src/rt/rust_sched_loop.cpp @@ -150,10 +150,10 @@ rust_sched_loop::release_task(rust_task *task) { rust_task * rust_sched_loop::schedule_task() { lock.must_have_lock(); - if (running_tasks.length() > 0) { - size_t k = rng_gen_u32(kernel, &rng); - size_t i = k % running_tasks.length(); - return (rust_task *)running_tasks[i]; + size_t tasks = running_tasks.length(); + if (tasks > 0) { + size_t i = (tasks > 1) ? (rng_gen_u32(kernel, &rng) % tasks) : 0; + return running_tasks[i]; } return NULL; }