Skip to content

Commit

Permalink
outline rng length assert
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jan 2, 2020
1 parent 13d1bd4 commit d723cee
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stdlib/Random/src/RNGs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ seed!(seed::Union{Integer,Vector{UInt32}}) = seed!(default_rng(), seed)
const THREAD_RNGs = MersenneTwister[]
@inline default_rng() = default_rng(Threads.threadid())
@noinline function default_rng(tid::Int)
@assert 0 < tid <= length(THREAD_RNGs)
0 < tid <= length(THREAD_RNGs) || _rng_length_assert()
if @inbounds isassigned(THREAD_RNGs, tid)
@inbounds MT = THREAD_RNGs[tid]
else
Expand All @@ -304,6 +304,8 @@ const THREAD_RNGs = MersenneTwister[]
end
return MT
end
@noinline _rng_length_assert() = @assert false "0 < tid <= length(THREAD_RNGs)"

function __init__()
resize!(empty!(THREAD_RNGs), Threads.nthreads()) # ensures that we didn't save a bad object
end
Expand Down

0 comments on commit d723cee

Please sign in to comment.