Skip to content

Commit

Permalink
lock complete! of MTable behind a SpinLock
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed Apr 22, 2024
1 parent 54de891 commit feca94e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/mtables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct MTable{T,I,V<:AbstractVector,M<:AbstractMatrix,Ms} <:
starof::Vector{I}
table::M
mstr::Ms
lock::Base.Threads.SpinLock
end

function MTable(
Expand All @@ -33,7 +34,7 @@ function MTable(
table = Matrix{T}(undef, dims)
@assert !isbitstype(T) || dims == (0, 0)

return MTable(elts, relts, starof, table, mstr)
return MTable(elts, relts, starof, table, mstr, Base.Threads.SpinLock())
end

Base.@propagate_inbounds function __absindex(mt::MTable, i::Integer)
Expand All @@ -55,7 +56,9 @@ Base.@propagate_inbounds function (mt::MTable)(i::Integer, j::Integer)
if checkbounds(Bool, mt.table, i, j)
@inbounds begin
if !__iscomputed(mt, i, j)
complete!(mt, i, j)
lock(mt.lock) do
return complete!(mt, i, j)
end
end
return mt.table[i, j]
end
Expand Down

0 comments on commit feca94e

Please sign in to comment.