|
1 | 1 | # In-Thunk Helpers |
2 | 2 |
|
| 3 | +struct DTaskTLS |
| 4 | + processor::Processor |
| 5 | + sch_uid::UInt |
| 6 | + sch_handle::Any # FIXME: SchedulerHandle |
| 7 | + task_spec::Vector{Any} # FIXME: TaskSpec |
| 8 | +end |
| 9 | + |
| 10 | +const DTASK_TLS = TaskLocalValue{Union{DTaskTLS,Nothing}}(()->nothing) |
| 11 | + |
3 | 12 | """ |
4 | | - task_processor() |
| 13 | + get_tls() -> DTaskTLS |
5 | 14 |
|
6 | | -Get the current processor executing the current Dagger task. |
| 15 | +Gets all Dagger TLS variable as a `DTaskTLS`. |
7 | 16 | """ |
8 | | -task_processor() = task_local_storage(:_dagger_processor)::Processor |
9 | | -@deprecate thunk_processor() task_processor() |
| 17 | +get_tls() = DTASK_TLS[]::DTaskTLS |
10 | 18 |
|
11 | 19 | """ |
12 | | - in_task() |
| 20 | + set_tls!(tls) |
13 | 21 |
|
14 | | -Returns `true` if currently executing in a [`DTask`](@ref), else `false`. |
| 22 | +Sets all Dagger TLS variables from `tls`, which may be a `DTaskTLS` or a `NamedTuple`. |
15 | 23 | """ |
16 | | -in_task() = haskey(task_local_storage(), :_dagger_sch_uid) |
17 | | -@deprecate in_thunk() in_task() |
| 24 | +function set_tls!(tls) |
| 25 | + DTASK_TLS[] = DTaskTLS(tls.processor, tls.sch_uid, tls.sch_handle, tls.task_spec) |
| 26 | +end |
18 | 27 |
|
19 | 28 | """ |
20 | | - get_tls() |
| 29 | + in_task() -> Bool |
21 | 30 |
|
22 | | -Gets all Dagger TLS variable as a `NamedTuple`. |
| 31 | +Returns `true` if currently executing in a [`DTask`](@ref), else `false`. |
23 | 32 | """ |
24 | | -get_tls() = ( |
25 | | - sch_uid=task_local_storage(:_dagger_sch_uid), |
26 | | - sch_handle=task_local_storage(:_dagger_sch_handle), |
27 | | - processor=task_processor(), |
28 | | - task_spec=task_local_storage(:_dagger_task_spec), |
29 | | -) |
| 33 | +in_task() = DTASK_TLS[] !== nothing |
| 34 | +@deprecate in_thunk() in_task() |
30 | 35 |
|
31 | 36 | """ |
32 | | - set_tls!(tls) |
| 37 | + task_processor() -> Processor |
33 | 38 |
|
34 | | -Sets all Dagger TLS variables from the `NamedTuple` `tls`. |
| 39 | +Get the current processor executing the current [`DTask`](@ref). |
35 | 40 | """ |
36 | | -function set_tls!(tls) |
37 | | - task_local_storage(:_dagger_sch_uid, tls.sch_uid) |
38 | | - task_local_storage(:_dagger_sch_handle, tls.sch_handle) |
39 | | - task_local_storage(:_dagger_processor, tls.processor) |
40 | | - task_local_storage(:_dagger_task_spec, tls.task_spec) |
41 | | -end |
| 41 | +task_processor() = get_tls().processor |
| 42 | +@deprecate thunk_processor() task_processor() |
0 commit comments