Skip to content

Commit 80f56e2

Browse files
committed
Restructure MiscAlgorithms, "remove" multi threading for now
1 parent dae2eeb commit 80f56e2

File tree

3 files changed

+44
-45
lines changed

3 files changed

+44
-45
lines changed

src/MiscAlgorithms/MiscAlgorithms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include("RuntimeAlgorithms.jl")
1+
include("ThreadPinnedAlgorithm.jl")

src/MiscAlgorithms/RuntimeAlgorithms.jl renamed to src/MiscAlgorithms/MultiThreadedAlgorithms.jl

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,3 @@
1-
export ThreadPinnedAlgorithm, ThreadPinnedAlgorithmParameter
2-
Base.@kwdef struct ThreadPinnedAlgorithmParameter <: AbstractImageReconstructionParameters
3-
threadID::Int64
4-
algo::AbstractImageReconstructionAlgorithm
5-
end
6-
7-
mutable struct ThreadPinnedAlgorithm <: AbstractImageReconstructionAlgorithm
8-
params::ThreadPinnedAlgorithmParameter
9-
recoTask::Union{Nothing,Task}
10-
taskLock::ReentrantLock
11-
inputChannel::Channel{Any}
12-
outputChannel::Channel{Any}
13-
end
14-
15-
ThreadPinnedAlgorithm(params::ThreadPinnedAlgorithmParameter) = ThreadPinnedAlgorithm(params, nothing, ReentrantLock(), Channel{Any}(Inf), Channel{Any}(Inf))
16-
17-
take!(algo::ThreadPinnedAlgorithm) = take!(algo.outputChannel)
18-
function put!(algo::ThreadPinnedAlgorithm, u)
19-
put!(algo.inputChannel, u)
20-
lock(algo.taskLock)
21-
try
22-
if isnothing(algo.recoTask) || istaskdone(algo.recoTask)
23-
algo.recoTask = @tspawnat algo.params.threadID pinnedRecoTask(algo)
24-
end
25-
finally
26-
unlock(algo.taskLock)
27-
end
28-
end
29-
function pinnedRecoTask(algo::ThreadPinnedAlgorithm)
30-
while isready(algo.inputChannel)
31-
result = nothing
32-
try
33-
put!(algo.params.algo, take!(algo.inputChannel))
34-
result = take!(algo.params.algo)
35-
catch e
36-
result = e
37-
end
38-
put!(algo.outputChannel, result)
39-
end
40-
end
41-
# TODO general async task, has to preserve order (cant just spawn task for each put)
42-
# TODO Timeout task with timeout options for put and take
43-
# TODO maybe can be cancelled?
44-
451
export AbstractMultiThreadedProcessing
462
abstract type AbstractMultiThreadedProcessing <: AbstractImageReconstructionAlgorithm end
473

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export ThreadPinnedAlgorithm, ThreadPinnedAlgorithmParameter
2+
Base.@kwdef struct ThreadPinnedAlgorithmParameter <: AbstractImageReconstructionParameters
3+
threadID::Int64
4+
algo::AbstractImageReconstructionAlgorithm
5+
end
6+
7+
mutable struct ThreadPinnedAlgorithm <: AbstractImageReconstructionAlgorithm
8+
params::ThreadPinnedAlgorithmParameter
9+
recoTask::Union{Nothing,Task}
10+
taskLock::ReentrantLock
11+
inputChannel::Channel{Any}
12+
outputChannel::Channel{Any}
13+
end
14+
15+
ThreadPinnedAlgorithm(params::ThreadPinnedAlgorithmParameter) = ThreadPinnedAlgorithm(params, nothing, ReentrantLock(), Channel{Any}(Inf), Channel{Any}(Inf))
16+
17+
take!(algo::ThreadPinnedAlgorithm) = take!(algo.outputChannel)
18+
function put!(algo::ThreadPinnedAlgorithm, u)
19+
put!(algo.inputChannel, u)
20+
lock(algo.taskLock)
21+
try
22+
if isnothing(algo.recoTask) || istaskdone(algo.recoTask)
23+
algo.recoTask = @tspawnat algo.params.threadID pinnedRecoTask(algo)
24+
end
25+
finally
26+
unlock(algo.taskLock)
27+
end
28+
end
29+
function pinnedRecoTask(algo::ThreadPinnedAlgorithm)
30+
while isready(algo.inputChannel)
31+
result = nothing
32+
try
33+
put!(algo.params.algo, take!(algo.inputChannel))
34+
result = take!(algo.params.algo)
35+
catch e
36+
result = e
37+
end
38+
put!(algo.outputChannel, result)
39+
end
40+
end
41+
# TODO general async task, has to preserve order (cant just spawn task for each put)
42+
# TODO Timeout task with timeout options for put and take
43+
# TODO maybe can be cancelled?

0 commit comments

Comments
 (0)