diff options
| author | bors <bors@rust-lang.org> | 2013-02-15 10:06:12 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-02-15 10:06:12 -0800 |
| commit | 0a1fcadc907341b1993b109c72384ab16b512d06 (patch) | |
| tree | 2dba6c3da13c97e4906145930436f10e9651d6aa /src/rt/rust_sched_loop.cpp | |
| parent | 9727008ed0772fc325e0822e74b429e4e7c09af0 (diff) | |
| parent | 9a76d718c709da7d69d3533e1b2019a768343af5 (diff) | |
| download | rust-0a1fcadc907341b1993b109c72384ab16b512d06.tar.gz rust-0a1fcadc907341b1993b109c72384ab16b512d06.zip | |
auto merge of #4958 : cpeterso/rust/reseed-rng, r=graydon
For Issue #4709: **c531506 rt: rand.rs expects `rust_next()` to return `uint32_t`, not `size_t`** rand.rs expects `rustrt::rand_next()` to return `u32`, but the `rand_next()` C function returns `size_t`: https://github.com/mozilla/rust/blob/ca71c6ec5bb8106121cbe33eec5a6a9ca7786039/src/libcore/rand.rs#L34 **f4320b6 move isaac RNG utility functions to new rust_rng.cpp file** **665e900 encapsulate isaac RNG in `rust_rng` struct** Move isaac's `randctx` into a `rust_rng` struct to make names similar to `rand::Rng` function names and prepare for auto-reseeding in the next commit. **9a78dc9 reseed `rust_rng` after generating 32KB** Precedents from other languages: * Haskell's `GenAutoReseed` generator reseeds itself after generating 32KB: http://hackage.haskell.org/packages/archive/DRBG/0.1.2/doc/html/Crypto-Random-DRBG.html#t:GenAutoReseed * Go's RNG reseeds itself after generating 1MB: https://code.google.com/p/go/source/browse/src/pkg/crypto/rand/rand_unix.go?name=go1.0.3#94 **9a76d71 don't deplete RNG entropy when there is only one runnable task** `rust_sched_loop::schedule_task()` unnecessarily calls `isaac_rand()` for the common case when there is only 1 runnable task, thus depleting RNG entropy and incurring unnecessary overhead.
Diffstat (limited to 'src/rt/rust_sched_loop.cpp')
| -rw-r--r-- | src/rt/rust_sched_loop.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/rt/rust_sched_loop.cpp b/src/rt/rust_sched_loop.cpp index 0d0eaaee962..7143bf88d46 100644 --- a/src/rt/rust_sched_loop.cpp +++ b/src/rt/rust_sched_loop.cpp @@ -41,7 +41,7 @@ rust_sched_loop::rust_sched_loop(rust_scheduler *sched, int id, bool killed) : name("main") { LOGPTR(this, "new dom", (uintptr_t)this); - isaac_init(kernel, &rctx, NULL); + rng_init(kernel, &rng, NULL); if (!tls_initialized) init_tls(); @@ -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 = isaac_rand(&rctx); - 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; } |
