Skip to content

Commit 2af3f10

Browse files
committed
task-tls: Tweaks and fixes, task_id helper
1 parent c07db4c commit 2af3f10

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/task-tls.jl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# In-Thunk Helpers
22

3-
struct DTaskTLS
3+
mutable struct DTaskTLS
44
processor::Processor
55
sch_uid::UInt
66
sch_handle::Any # FIXME: SchedulerHandle
@@ -10,6 +10,8 @@ end
1010

1111
const DTASK_TLS = TaskLocalValue{Union{DTaskTLS,Nothing}}(()->nothing)
1212

13+
Base.copy(tls::DTaskTLS) = DTaskTLS(tls.processor, tls.sch_uid, tls.sch_handle, tls.task_spec, tls.cancel_token)
14+
1315
"""
1416
get_tls() -> DTaskTLS
1517
@@ -32,22 +34,29 @@ end
3234
Returns `true` if currently executing in a [`DTask`](@ref), else `false`.
3335
"""
3436
in_task() = DTASK_TLS[] !== nothing
35-
@deprecate in_thunk() in_task()
37+
@deprecate(in_thunk(), in_task())
38+
39+
"""
40+
task_id() -> Int
41+
42+
Returns the ID of the current [`DTask`](@ref).
43+
"""
44+
task_id() = get_tls().sch_handle.thunk_id.id
3645

3746
"""
3847
task_processor() -> Processor
3948
4049
Get the current processor executing the current [`DTask`](@ref).
4150
"""
4251
task_processor() = get_tls().processor
43-
@deprecate thunk_processor() task_processor()
52+
@deprecate(thunk_processor(), task_processor())
4453

4554
"""
4655
task_cancelled() -> Bool
4756
4857
Returns `true` if the current [`DTask`](@ref) has been cancelled, else `false`.
4958
"""
50-
task_cancelled() = get_tls().cancel_token.cancelled[]
59+
task_cancelled() = is_cancelled(get_tls().cancel_token)
5160

5261
"""
5362
task_may_cancel!()
@@ -59,3 +68,10 @@ function task_may_cancel!()
5968
throw(InterruptException())
6069
end
6170
end
71+
72+
"""
73+
task_cancel!()
74+
75+
Cancels the current [`DTask`](@ref).
76+
"""
77+
task_cancel!() = cancel!(get_tls().cancel_token)

0 commit comments

Comments
 (0)