-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy paththreadproc.jl
43 lines (41 loc) · 1.32 KB
/
threadproc.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
ThreadProc <: Processor
Julia CPU (OS) thread, identified by Julia thread ID.
"""
struct ThreadProc <: Processor
owner::Int
tid::Int
end
iscompatible(proc::ThreadProc, opts, f, args...) = true
iscompatible_func(proc::ThreadProc, opts, f) = true
iscompatible_arg(proc::ThreadProc, opts, x) = true
function execute!(proc::ThreadProc, @nospecialize(f), @nospecialize(args...); @nospecialize(kwargs...))
tls = get_tls()
# FIXME: Use return type of the call to specialize container
result = Ref{Any}()
task = Task() do
set_tls!(tls)
TimespanLogging.prof_task_put!(tls.sch_handle.thunk_id.id)
result[] = @invokelatest f(args...; kwargs...)
return
end
set_task_tid!(task, proc.tid)
schedule(task)
try
fetch(task)
return result[]
catch err
if err isa InterruptException
if !istaskdone(task)
# Propagate cancellation signal
Threads.@spawn Base.throwto(task, InterruptException())
end
end
err, frames = Base.current_exceptions(task)[1]
rethrow(CapturedException(err, frames))
end
end
get_parent(proc::ThreadProc) = OSProc(proc.owner)
default_enabled(proc::ThreadProc) = true
short_name(proc::ThreadProc) = "W: $(proc.owner), TID: $(proc.tid)"
# TODO: ThreadGroupProc?