Skip to content

Commit

Permalink
Add wait, isready, lock and unlock to algo-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nHackel committed Dec 12, 2024
1 parent 70910e4 commit fbc4270
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/AbstractImageReconstruction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Observables
using Scratch
using LRUCache

import Base: put!, take!, fieldtypes, fieldtype, ismissing, propertynames, parent, hash, wait, isready
import Base: put!, take!, fieldtypes, fieldtype, ismissing, propertynames, parent, hash, wait, isready, lock, unlock

include("AlgorithmInterface.jl")
include("StructTransforms.jl")
Expand Down
47 changes: 44 additions & 3 deletions src/AlgorithmInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,57 @@ put!(algo::AbstractImageReconstructionAlgorithm, inputs...) = error("$(typeof(al
Remove and return a stored result from the algorithm `algo`. Blocks until a result is available.
"""
take!(algo::AbstractImageReconstructionAlgorithm) = error("$(typeof(algo)) must implement take!")
"""
isready(algo::AbstractImageReconstructionAlgorithm)
Determine if the algorithm `algo` has a result available.
"""
isready(algo::AbstractImageReconstructionAlgorithm) = error("$(typeof(algo)) must implement isready")
"""
wait(algo::AbstractImageReconstructionAlgorithm)
Wait for a result to be available from the specified `algo`.
"""
wait(algo::AbstractImageReconstructionAlgorithm) = error("$(typeof(algo)) must implement wait")
"""
lock(algo::AbstractImageReconstructionAlgorithm)
Acquire a lock on the algorithm `algo`. If the lock is already acquired, wait until it is released.
Each `lock` must be matched with a `unlock`.
"""
lock(algo::AbstractImageReconstructionAlgorithm) = error("$(typeof(algo)) must implement lock")
"""
unlock(algo::AbstractImageReconstructionAlgorithm)
Release a lock on the algorithm `algo`.
"""
unlock(algo::AbstractImageReconstructionAlgorithm) = error("$(typeof(algo)) must implement unlock")
"""
lock(fn, algo::AbstractImageReconstructionAlgorithm)
Acquire the `lock` on `algo`, execute `fn` and release the `lock` afterwards.
"""
function lock(fn, algo::AbstractImageReconstructionAlgorithm)
lock(algo)
try
fn()
finally
unlock(algo)
end
end

export reconstruct
"""
reconstruct(algo::T, u) where {T<:AbstractImageReconstructionAlgorithm}
Reconstruct an image from input `u` using algorithm `algo`.
Reconstruct an image from input `u` using algorithm `algo`. The `àlgo` will be `lock`ed until the result is available or an error occurs.
"""
function reconstruct(algo::T, u) where {T<:AbstractImageReconstructionAlgorithm}
put!(algo, u)
return take!(algo)
lock(algo) do
put!(algo, u)
return take!(algo)
end
end

export process
Expand Down

0 comments on commit fbc4270

Please sign in to comment.