Skip to content

Commit

Permalink
Tweak cache pidlocking pt. 2 (#50254)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Jun 22, 2023
1 parent ec33194 commit 07f0525
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2226,14 +2226,14 @@ function compilecache_dir(pkg::PkgId)
return joinpath(DEPOT_PATH[1], entrypath)
end

function compilecache_path(pkg::PkgId, prefs_hash::UInt64)::String
function compilecache_path(pkg::PkgId, prefs_hash::UInt64; project::String=something(Base.active_project(), ""))::String
entrypath, entryfile = cache_file_entry(pkg)
cachepath = joinpath(DEPOT_PATH[1], entrypath)
isdir(cachepath) || mkpath(cachepath)
if pkg.uuid === nothing
abspath(cachepath, entryfile) * ".ji"
else
crc = _crc32c(something(Base.active_project(), ""))
crc = _crc32c(project)
crc = _crc32c(unsafe_string(JLOptions().image_file), crc)
crc = _crc32c(unsafe_string(JLOptions().julia_bin), crc)
crc = _crc32c(ccall(:jl_cache_flags, UInt8, ()), crc)
Expand Down Expand Up @@ -2823,17 +2823,17 @@ global mkpidlock_hook
global trymkpidlock_hook
global parse_pidfile_hook

# The preferences hash is only known after precompilation so just assume no preferences
# meaning that if all other conditions are equal, the same package cannot be precompiled
# with different preferences at the same time.
compilecache_pidfile_path(pkg::PkgId) = compilecache_path(pkg, UInt64(0)) * ".pidfile"
# The preferences hash is only known after precompilation so just assume no preferences.
# Also ignore the active project, which means that if all other conditions are equal,
# the same package cannot be precompiled from different projects and/or different preferences at the same time.
compilecache_pidfile_path(pkg::PkgId) = compilecache_path(pkg, UInt64(0); project="") * ".pidfile"

# Allows processes to wait if another process is precompiling a given source already.
# The lock file is deleted and precompilation will proceed after `stale_age` seconds if
# - the locking process no longer exists
# - the lock is held by another host, since processes cannot be checked remotely
# or after `stale_age * 25` seconds if it does still exist.
function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String; stale_age=60)
# or after `stale_age * 25` seconds if the process does still exist.
function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String; stale_age=300)
if @isdefined(mkpidlock_hook) && @isdefined(trymkpidlock_hook) && @isdefined(parse_pidfile_hook)
pidfile = compilecache_pidfile_path(pkg)
cachefile = invokelatest(trymkpidlock_hook, f, pidfile; stale_age)
Expand Down

0 comments on commit 07f0525

Please sign in to comment.