@@ -29,18 +29,44 @@ function init_eager()
29
29
end
30
30
end
31
31
32
- " Sets the scheduler's cached pressure indicator for the specified worker."
33
- set_pressure! (h:: SchedulerHandle , pid:: Int , proctype:: Type , pressure:: Int ) =
34
- exec! (_set_pressure!, h, pid, proctype, pressure)
35
- function _set_pressure! (ctx, state, task, tid, (pid, proctype, pressure))
36
- state. worker_pressure[pid][proctype] = pressure
37
- ACTIVE_TASKS[state. uid][proctype] = pressure # HACK-ish
32
+ " Adjusts the scheduler's cached pressure indicator for the specified worker by
33
+ the specified amount."
34
+ function adjust_pressure! (h:: SchedulerHandle , proctype:: Type , pressure)
35
+ uid = Dagger. get_tls (). sch_uid
36
+ lock (ACTIVE_TASKS_LOCK) do
37
+ ACTIVE_TASKS[uid][proctype][] += pressure
38
+ end
39
+ exec! (_adjust_pressure!, h, myid (), proctype, pressure)
40
+ end
41
+ function _adjust_pressure! (ctx, state, task, tid, (pid, proctype, pressure))
42
+ state. worker_pressure[pid][proctype] += pressure
38
43
nothing
39
44
end
40
45
46
+ " Allows a thunk to safely wait on another thunk, by temporarily reducing its
47
+ effective pressure to 0."
48
+ function thunk_yield (f)
49
+ if Dagger. in_thunk ()
50
+ h = sch_handle ()
51
+ tls = Dagger. get_tls ()
52
+ proctype = typeof (tls. processor)
53
+ util = tls. utilization
54
+ adjust_pressure! (h, proctype, - util)
55
+ try
56
+ f ()
57
+ finally
58
+ adjust_pressure! (h, proctype, util)
59
+ end
60
+ else
61
+ f ()
62
+ end
63
+ end
64
+
41
65
function eager_thunk ()
42
66
h = sch_handle ()
43
- set_pressure! (h, 1 , Dagger. ThreadProc, 0 ) # HACK: Don't apply pressure from this thunk
67
+ util = Dagger. get_tls (). utilization
68
+ # Don't apply pressure from this thunk
69
+ adjust_pressure! (h, Dagger. ThreadProc, - util)
44
70
while isopen (EAGER_THUNK_CHAN)
45
71
try
46
72
future, uid, f, args, opts = take! (EAGER_THUNK_CHAN)
0 commit comments