Skip to content

Commit dae2eeb

Browse files
committed
Update documentation for wait, locked & co
1 parent fbc4270 commit dae2eeb

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

docs/src/API/api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ AbstractImageReconstruction.AbstractImageReconstructionAlgorithm
88
AbstractImageReconstruction.reconstruct
99
Base.put!(::AbstractImageReconstructionAlgorithm, ::Any)
1010
Base.take!(::AbstractImageReconstructionAlgorithm)
11+
Base.lock(::AbstractImageReconstructionAlgorithm)
12+
Base.unlock(::AbstractImageReconstructionAlgorithm)
13+
Base.isready(::AbstractImageReconstructionAlgorithm)
14+
Base.wait(::AbstractImageReconstructionAlgorithm)
1115
AbstractImageReconstruction.AbstractImageReconstructionParameters
1216
AbstractImageReconstruction.process
1317
AbstractImageReconstruction.parameter

docs/src/literate/example/2_direct.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,20 @@ end
5353
# And they implement a method to retrieve the used parameters:
5454
AbstractImageReconstruction.parameter(algo::DirectRadonAlgorithm) = algo.parameter
5555

56-
# And implement the `put!` and `take!` functions, mimicking the behavior of a FIFO channel:
56+
# Algorithms are assumed to be stateful. To ensure thread safety, we need to implement the `lock` and `unlock` functions. We will use the `output` channel as a lock:
57+
Base.lock(algo::DirectRadonAlgorithm) = lock(algo.output)
58+
Base.unlock(algo::DirectRadonAlgorithm) = unlock(algo.output)
59+
60+
# And implement the `put!` and `take!` functions, mimicking the behavior of a FIFO channel for reconstructions:
5761
Base.take!(algo::DirectRadonAlgorithm) = Base.take!(algo.output)
58-
function Base.put!(algo::DirectRadonAlgorithm, data::AbstractArray{T, 4}) where {T}
59-
lock(algo.output) do
62+
function Base.put!(algo::DirectRadonAlgorithm, data::AbstractArray{T, 4}) where {T}
63+
lock(algo) do
6064
put!(algo.output, process(algo, algo.parameter, data))
6165
end
6266
end
6367

6468
# The way the behaviour is implemented here, the algorithm does not buffer any inputs and instead blocks until the currenct reconstruction is done. Outputs are stored until they are retrieved.
69+
70+
# With `wait` and `isready` we can check if the algorithm is currently processing data or if it is ready to accept new inputs:
71+
Base.wait(algo::DirectRadonAlgorithm) = wait(algo.output)
72+
Base.isready(algo::DirectRadonAlgorithm) = isready(algo.output)

docs/src/literate/example/4_iterative.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,15 @@ end
7373
# Our algorithm is not type stable. To fix this, we would need to know the element type of the sinograms during construction. Which is possible with a different parameterization of the algorithm. We will not do this here.
7474
# Often times the performance impact of this is negligible as the critical sections are in the preprocessing or the iterative solver, especially since we still dispatch on the operator.
7575

76-
# To finish up the implementation we need to implement the `put!`, `take!` and `parameters` functions:
76+
# To finish up the implementation we need to implement the remaining runtime related functions:
7777
Base.take!(algo::IterativeRadonAlgorithm) = Base.take!(algo.output)
7878
function Base.put!(algo::IterativeRadonAlgorithm, data::AbstractArray{T, 4}) where {T}
7979
lock(algo.output) do
8080
put!(algo.output, process(algo, algo.parameter, data))
8181
end
8282
end
83+
Base.lock(algo::IterativeRadonAlgorithm) = lock(algo.output)
84+
Base.unlock(algo::IterativeRadonAlgorithm) = unlock(algo.output)
85+
Base.isready(algo::IterativeRadonAlgorithm) = isready(algo.output)
86+
Base.wait(algo::IterativeRadonAlgorithm) = wait(algo.output)
8387
AbstractImageReconstruction.parameter(algo::IterativeRadonAlgorithm) = algo.parameter

docs/src/literate/example/example_include_data.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ angles, shape, sinograms, images = isDataDefined ? (angles, shape, sinograms, im
3131
sinograms[:, :, :, i] = Array(RadonKA.radon(images[:, :, :, i], angles))
3232
end
3333
return angles, shape, sinograms, images
34-
end;
34+
end
35+
nothing

0 commit comments

Comments
 (0)