Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/cancellation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ alternative to Ctrl+C, as it cooperates with the scheduler and runtime and
avoids unintended side effects.
"""
function cancel!(task::DTask; force::Bool=false, graceful::Bool=true, halt_sch::Bool=false)
tid = lock(Dagger.Sch.EAGER_ID_MAP) do id_map
id_map[task.uid]
end
cancel!(tid; force, graceful, halt_sch)
# Eager DTask uid and Sch thunk id are the same value.
cancel!(Int(task.uid); force, graceful, halt_sch)
end
function cancel!(tid::Union{Int,Nothing}=nothing;
force::Bool=false, graceful::Bool=true, halt_sch::Bool=false)
Expand Down
14 changes: 4 additions & 10 deletions src/sch/eager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const EAGER_INIT = Threads.Atomic{Bool}(false)
# Condition variable used to synchronize EAGER_STATE changes.
# Waiters must hold this lock, check EAGER_STATE[], and wait in a loop.
const EAGER_STATE_LOCK = Threads.Condition()
const EAGER_ID_MAP = LockedObject(Dict{UInt64,Int}())
const EAGER_CONTEXT = Ref{Union{Context,Nothing}}(nothing)
const EAGER_STATE = Ref{Union{ComputeState,Nothing}}(nothing)

Expand Down Expand Up @@ -68,9 +67,6 @@ function init_eager()
EAGER_STATE[] = nothing
notify(EAGER_STATE_LOCK; all=true)
end
lock(EAGER_ID_MAP) do id_map
empty!(id_map)
end
end)

# Wait for eager_thunk to set EAGER_STATE[].
Expand Down Expand Up @@ -141,15 +137,13 @@ function thunk_yield(f)
end

function _find_thunk(e::Dagger.DTask)
tid = lock(EAGER_ID_MAP) do id_map
id_map[e.uid]
end
# Eager DTask uids share the Sch thunk id counter (`thunk.id = Int(uid)`).
tid = Int(e.uid)
lock(EAGER_STATE[].lock) do
lock(EAGER_STATE[].thunk_dict) do d
unwrap_weak_checked(d[tid])
end
end
end
Dagger.task_id(t::Dagger.DTask) = lock(EAGER_ID_MAP) do id_map
id_map[t.uid]
end
# Eager DTask uid and Sch thunk id are the same value.
Dagger.task_id(t::Dagger.DTask) = Int(t.uid)
Loading
Loading