Skip to content

Commit

Permalink
use a Threads.Atomic counter instead
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Jul 21, 2021
1 parent a24fb7e commit 6cd8d97
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ function __init__()
if haskey(ENV, "JULIA_MAX_NUM_PRECOMPILE_FILES")
MAX_NUM_PRECOMPILE_FILES[] = parse(Int, ENV["JULIA_MAX_NUM_PRECOMPILE_FILES"])
end
append!(empty!(TIMING_IMPORTS), zeros(Int, Threads.nthreads()))
nothing
end

Expand Down
4 changes: 2 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ function _require_from_serialized(path::String)
end

# use an Int counter so that nested @time_imports calls all remain open
const TIMING_IMPORTS = Int[] # initialized in __init__
const TIMING_IMPORTS = Threads.Atomic{Int}(0)

# returns `true` if require found a precompile cache for this sourcepath, but couldn't load it
# returns `false` if the module isn't known to be precompilable
Expand Down Expand Up @@ -859,7 +859,7 @@ function _require_search_from_serialized(pkg::PkgId, sourcepath::String, depth::
if isa(restored, Exception)
@debug "Deserialization checks failed while attempting to load cache from $path_to_try" exception=restored
else
if TIMING_IMPORTS[Threads.threadid()] > 0
if TIMING_IMPORTS[] > 0
elapsed = round((time_ns() - t_before) / 1e6, digits = 1)
tree_prefix = depth == 0 ? "" : "$(" "^(depth-1))"
print("$(lpad(elapsed, 9)) ms ")
Expand Down
4 changes: 2 additions & 2 deletions stdlib/InteractiveUtils/src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ end
macro time_imports(ex)
quote
try
Base.TIMING_IMPORTS[Threads.threadid()] += 1
Base.TIMING_IMPORTS[] += 1
$(esc(ex))
finally
Base.TIMING_IMPORTS[Threads.threadid()] -= 1
Base.TIMING_IMPORTS[] -= 1
end
end
end
Expand Down

0 comments on commit 6cd8d97

Please sign in to comment.