Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions base/lock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,10 @@ mutable struct OncePerProcess{T, F} <: Function
end
OncePerProcess{T}(initializer::F) where {T, F} = OncePerProcess{T, F}(initializer)
OncePerProcess(initializer) = OncePerProcess{Base.promote_op(initializer), typeof(initializer)}(initializer)
@inline function (once::OncePerProcess{T})() where T
@inline function (once::OncePerProcess{T,F})() where {T,F}
state = (@atomic :acquire once.state)
if state != PerStateHasrun
(@noinline function init_perprocesss(once, state)
(@noinline function init_perprocesss(once::OncePerProcess{T,F}, state::UInt8) where {T,F}
state == PerStateErrored && error("OncePerProcess initializer failed previously")
once.allow_compile_time || __precompile__(false)
lock(once.lock)
Expand Down Expand Up @@ -818,14 +818,14 @@ mutable struct OncePerThread{T, F} <: Function
end
OncePerThread{T}(initializer::F) where {T, F} = OncePerThread{T,F}(initializer)
OncePerThread(initializer) = OncePerThread{Base.promote_op(initializer), typeof(initializer)}(initializer)
@inline (once::OncePerThread)() = once[Threads.threadid()]
@inline function getindex(once::OncePerThread, tid::Integer)
@inline (once::OncePerThread{T,F})() where {T,F} = once[Threads.threadid()]
@inline function getindex(once::OncePerThread{T,F}, tid::Integer) where {T,F}
tid = Int(tid)
ss = @atomic :acquire once.ss
xs = @atomic :monotonic once.xs
# n.b. length(xs) >= length(ss)
if tid <= 0 || tid > length(ss) || (@atomic :acquire ss[tid]) != PerStateHasrun
(@noinline function init_perthread(once, tid)
(@noinline function init_perthread(once::OncePerThread{T,F}, tid::Int) where {T,F}
local ss = @atomic :acquire once.ss
local xs = @atomic :monotonic once.xs
local len = length(ss)
Expand Down Expand Up @@ -933,6 +933,6 @@ mutable struct OncePerTask{T, F} <: Function
OncePerTask{T,F}(initializer::F) where {T, F} = new{T,F}(initializer)
OncePerTask(initializer) = new{Base.promote_op(initializer), typeof(initializer)}(initializer)
end
@inline function (once::OncePerTask{T})() where {T}
@inline function (once::OncePerTask{T,F})() where {T,F}
get!(once.initializer, task_local_storage(), once)::T
end
9 changes: 8 additions & 1 deletion test/trimming/hello.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
module MyApp

world::String = "world!"
const str = OncePerProcess{String}() do
return "Hello, " * world
end

Base.@ccallable function main()::Cint
println(Core.stdout, "Hello, world!")
println(Core.stdout, str())
return 0
end

end