@@ -3,7 +3,7 @@ struct ThreadTask
3
3
end
4
4
Base. pointer (tt:: ThreadTask ) = tt. p
5
5
6
- @inline taskpointer (tid:: T ) where {T} = THREADPOOLPTR[] + tid* (THREADBUFFERSIZE% T)
6
+ @inline taskpointer (tid:: T ) where {T} = THREADPOOLPTR[] + tid * (THREADBUFFERSIZE % T)
7
7
8
8
@inline function _call (p:: Ptr{UInt} )
9
9
fptr = load (p + sizeof (UInt), Ptr{Cvoid})
@@ -23,25 +23,30 @@ function (tt::ThreadTask)()
23
23
p = pointer (tt)
24
24
max_wait = one (UInt32) << 20
25
25
wait_counter = max_wait
26
- GC. @preserve THREADPOOL begin
27
- while true
28
- if _atomic_state (p) == TASK
29
- _call (p)
30
- wait_counter = zero (UInt32)
31
- continue
32
- end
33
- pause ()
34
- if (wait_counter += one (UInt32)) > max_wait
35
- wait_counter = zero (UInt32)
36
- _atomic_cas_cmp! (p, SPIN, WAIT) && Base. wait ()
26
+ try
27
+ GC. @preserve THREADPOOL begin
28
+ while true
29
+ if _atomic_state (p) == TASK
30
+ _call (p)
31
+ wait_counter = zero (UInt32)
32
+ continue
33
+ end
34
+ pause ()
35
+ if (wait_counter += one (UInt32)) > max_wait
36
+ wait_counter = zero (UInt32)
37
+ _atomic_cas_cmp! (p, SPIN, WAIT) && Base. wait ()
38
+ end
37
39
end
38
40
end
41
+ catch
42
+ show (stderr , MIME " text/plain" (), Base. current_task ())
43
+ println ()
39
44
end
40
45
end
41
46
42
47
function _sleep (p:: Ptr{UInt} )
43
48
_atomic_store! (p, WAIT)
44
- Base. wait ();
49
+ Base. wait ()
45
50
return nothing
46
51
end
47
52
@@ -58,7 +63,7 @@ function sleep_all_tasks()
58
63
end
59
64
60
65
# 1-based tid, pushes into task 2-nthreads()
61
- @noinline function wake_thread! (_tid:: T ) where {T <: Integer }
66
+ @noinline function wake_thread! (_tid:: T ) where {T<: Integer }
62
67
tid = _tid % Int
63
68
tidp1 = tid + one (tid)
64
69
assume (unsigned (length (Base. Workqueues)) > unsigned (tid))
70
75
@noinline function checktask (tid)
71
76
t = TASKS[tid]
72
77
if istaskfailed (t)
73
- show (stderr , MIME " text/plain" (), t)
74
- println ()
75
78
initialize_task (tid)
76
79
return true
77
80
end
78
81
yield ()
79
82
false
80
83
end
81
84
# 1-based tid
85
+ @inline tasktid (p:: Ptr{UInt} ) = (p - THREADPOOLPTR[]) ÷ (THREADBUFFERSIZE)
82
86
@inline wait (tid:: Integer ) = wait (taskpointer (tid), tid)
83
- @inline wait (p:: Ptr{UInt} ) = wait (p, (p - THREADPOOLPTR[]) ÷ (THREADBUFFERSIZE ))
87
+ @inline wait (p:: Ptr{UInt} ) = wait (p, tasktid (p ))
84
88
@inline function wait (p:: Ptr{UInt} , tid)
85
89
counter = 0x00000000
86
90
while _atomic_state (p) == TASK
0 commit comments