@@ -702,10 +702,6 @@ mutable struct OncePerProcess{T, F} <: Function
702
702
703
703
function OncePerProcess {T,F} (initializer:: F ) where {T, F}
704
704
once = new {T,F} (nothing , PerStateInitial, true , initializer, ReentrantLock ())
705
- ccall (:jl_set_precompile_field_replace , Cvoid, (Any, Any, Any),
706
- once, :value , nothing )
707
- ccall (:jl_set_precompile_field_replace , Cvoid, (Any, Any, Any),
708
- once, :state , PerStateInitial)
709
705
return once
710
706
end
711
707
end
@@ -721,6 +717,10 @@ OncePerProcess(initializer) = OncePerProcess{Base.promote_op(initializer), typeo
721
717
try
722
718
state = @atomic :monotonic once. state
723
719
if state == PerStateInitial
720
+ ccall (:jl_set_precompile_field_replace , Cvoid, (Any, Any, Any),
721
+ once, :value , nothing )
722
+ ccall (:jl_set_precompile_field_replace , Cvoid, (Any, Any, Any),
723
+ once, :state , PerStateInitial)
724
724
once. value = once. initializer ()
725
725
elseif state == PerStateErrored
726
726
error (" OncePerProcess initializer failed previously" )
@@ -809,10 +809,6 @@ mutable struct OncePerThread{T, F} <: Function
809
809
function OncePerThread {T,F} (initializer:: F ) where {T, F}
810
810
xs, ss = AtomicMemory {T} (), AtomicMemory {UInt8} ()
811
811
once = new {T,F} (xs, ss, initializer)
812
- ccall (:jl_set_precompile_field_replace , Cvoid, (Any, Any, Any),
813
- once, :xs , xs)
814
- ccall (:jl_set_precompile_field_replace , Cvoid, (Any, Any, Any),
815
- once, :ss , ss)
816
812
return once
817
813
end
818
814
end
@@ -849,6 +845,12 @@ OncePerThread(initializer) = OncePerThread{Base.promote_op(initializer), typeof(
849
845
ss = @atomic :monotonic once. ss
850
846
xs = @atomic :monotonic once. xs
851
847
if tid > length (ss)
848
+ if length (ss) == 0 # We are the first to initialize
849
+ ccall (:jl_set_precompile_field_replace , Cvoid, (Any, Any, Any),
850
+ once, :xs , xs)
851
+ ccall (:jl_set_precompile_field_replace , Cvoid, (Any, Any, Any),
852
+ once, :ss , ss)
853
+ end
852
854
@assert len <= length (ss) <= length (newss) " logical constraint violation"
853
855
fill_monotonic! (newss, PerStateInitial)
854
856
xs = copyto_monotonic! (newxs, xs)
0 commit comments