Skip to content

Commit

Permalink
Make some global variables constant
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Jan 25, 2022
1 parent ed87f07 commit 577a245
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Sandbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ include("Docker.jl")
# Load the UserNamespace executor
include("UserNamespaces.jl")

all_executors = Type{<:SandboxExecutor}[
const all_executors = Type{<:SandboxExecutor}[
# We always prefer the UserNamespaces executor, if we can use it,
# and the unprivileged one most of all. Only after that do we try `docker`.
UnprivilegedUserNamespacesExecutor,
Expand Down Expand Up @@ -89,16 +89,15 @@ function select_executor(verbose::Bool)
error("Could not find any available executors for $(triplet(HostPlatform()))!")
end

_preferred_executor = nothing
const _preferred_executor = Ref{Union{Nothing, all_executors...}}(nothing)
const _preferred_executor_lock = ReentrantLock()
function preferred_executor(;verbose::Bool = false)
lock(_preferred_executor_lock) do
# If we've already asked this question, return the old answer
global _preferred_executor
if _preferred_executor === nothing
_preferred_executor = select_executor(verbose)
if _preferred_executor[] === nothing
_preferred_executor[] = select_executor(verbose)
end
return _preferred_executor
return _preferred_executor[]
end
end

Expand Down

0 comments on commit 577a245

Please # to comment.