Skip to content

Commit

Permalink
Remove StateIndexVector
Browse files Browse the repository at this point in the history
  • Loading branch information
hanakl committed Sep 25, 2024
1 parent c11673f commit 6388b6f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
3 changes: 1 addition & 2 deletions src/ProtocolZoo/ProtocolZoo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ end
if isnothing(a_) || isnothing(b_)
if isnothing(prot.retry_lock_time)
@debug "EntanglerProt between $(prot.nodeA) and $(prot.nodeB)|round $(round): Failed to find free slots. \nGot:\n1. \t $a_ \n2.\t $b_ \n waiting..."
@yield lock(prot.nodeA.stateindices.waiter)
@yield lock(prot.nodeB.stateindices.waiter)
@yield lock(prot.nodeA.tag_waiter) | lock(prot.nodeB.tag_waiter)
else
@debug "EntanglerProt between $(prot.nodeA) and $(prot.nodeB)|round $(round): Failed to find free slots. \nGot:\n1. \t $a_ \n2.\t $b_ \n retrying..."
@yield timeout(prot.sim, prot.retry_lock_time)
Expand Down
36 changes: 1 addition & 35 deletions src/states_registers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,6 @@
# TODO better constructors
# TODO am I overusing Ref

import Base: getindex, setindex!, size, length, eltype

"""Vector with a semaphore where processes can wait on until there's a change in the vector"""
struct StateIndexVector <: AbstractVector{Int64}
data::Vector{Int}
waiter::AsymmetricSemaphore
end

function StateIndexVector(data::Vector{Int})
env = ConcurrentSim.Simulation()
return StateIndexVector(data, AsymmetricSemaphore(env))
end

function getindex(vec::StateIndexVector, index::Int)
return vec.data[index]
end

function setindex!(vec::StateIndexVector, value::Int, index::Int)
vec.data[index] = value
unlock(vec.waiter)
end

function size(vec::StateIndexVector)
return size(vec.data)
end

function length(vec::StateIndexVector)
return length(vec.data)
end

function eltype(::Type{StateIndexVector})
return Int64
end

struct StateRef
state::Base.RefValue{Any} # TODO it would be nice if this was not abstract but `uptotime!` converts between types... maybe make StateRef{T} state::RefValue{T} and a new function that swaps away the backpointers in the appropriate registers
registers::Vector{Any} # TODO Should be Vector{Register}, but right now we occasionally set it to nothing to deal with padded storage
Expand Down Expand Up @@ -68,7 +34,7 @@ function Register(traits, reprs, bg, sr, si, at)
end

Register(traits,reprs,bg,sr,si) = Register(traits,reprs,bg,sr,si,zeros(length(traits)))
Register(traits,reprs,bg) = Register(traits,reprs,bg,fill(nothing,length(traits)),StateIndexVector(zeros(Int,length(traits))),zeros(length(traits)))
Register(traits,reprs,bg) = Register(traits,reprs,bg,fill(nothing,length(traits)),zeros(Int,length(traits)),zeros(length(traits)))
Register(traits,bg::Base.AbstractVecOrTuple{<:Union{Nothing,<:AbstractBackground}}) = Register(traits,default_repr.(traits),bg)
Register(traits,reprs::Base.AbstractVecOrTuple{<:AbstractRepresentation}) = Register(traits,reprs,fill(nothing,length(traits)))
Register(traits) = Register(traits,default_repr.(traits))
Expand Down

0 comments on commit 6388b6f

Please sign in to comment.