11struct Copy{P} end
22function (:: Copy{P} )(p:: Ptr{UInt} ) where {P}
3- _, (ptry,ptrx,N) = ThreadingUtilities. load (p, P, 2 * sizeof (UInt))
3+ _, (ptry, ptrx, N) = ThreadingUtilities. load (p, P, 2 * sizeof (UInt))
44 N > 0 || throw (" This function throws if N == 0 for testing purposes." )
55 @simd ivdep for n ∈ 1 : N
66 unsafe_store! (ptry, unsafe_load (ptrx, n), n)
@@ -20,18 +20,18 @@ function setup_copy!(p, y, x)
2020 px = pointer (x)
2121 fptr = copy_ptr (py, px)
2222 offset = ThreadingUtilities. store! (p, fptr, sizeof (UInt))
23- ThreadingUtilities. store! (p, (py,px,N), offset)
23+ ThreadingUtilities. store! (p, (py, px, N), offset)
2424end
2525
2626@inline launch_thread_copy! (tid, y, x) = ThreadingUtilities. launch (setup_copy!, tid, y, x)
2727
2828function test_copy (tid, N = 100_000 )
29- a = rand (N);
30- b = rand (N);
31- c = rand (N);
32- x = similar (a) .= NaN ;
33- y = similar (b) .= NaN ;
34- z = similar (c) .= NaN ;
29+ a = rand (N)
30+ b = rand (N)
31+ c = rand (N)
32+ x = similar (a) .= NaN
33+ y = similar (b) .= NaN
34+ z = similar (c) .= NaN
3535 GC. @preserve a b c x y z begin
3636 launch_thread_copy! (tid, x, a)
3737 yield ()
5353 @test unsafe_load (Ptr {UInt32} (ThreadingUtilities. taskpointer (tid))) == 0x00000001
5454 end
5555 @test all (eachindex (ThreadingUtilities. TASKS)) do tid
56- ThreadingUtilities. load (ThreadingUtilities. taskpointer (tid), ThreadingUtilities. ThreadState) === ThreadingUtilities. WAIT
56+ ThreadingUtilities. load (
57+ ThreadingUtilities. taskpointer (tid),
58+ ThreadingUtilities. ThreadState,
59+ ) === ThreadingUtilities. WAIT
5760 end
5861 @test all (eachindex (ThreadingUtilities. TASKS)) do tid
59- ThreadingUtilities. _atomic_load (reinterpret (Ptr{UInt32}, ThreadingUtilities. taskpointer (tid))) === reinterpret (UInt32, ThreadingUtilities. WAIT)
62+ ThreadingUtilities. _atomic_load (
63+ reinterpret (Ptr{UInt32}, ThreadingUtilities. taskpointer (tid)),
64+ ) === reinterpret (UInt32, ThreadingUtilities. WAIT)
6065 end
6166 foreach (test_copy, eachindex (ThreadingUtilities. TASKS))
62-
63- x = rand (UInt, 3 );
67+
68+ x = rand (UInt, 3 )
6469 GC. @preserve x begin
6570 ThreadingUtilities. _atomic_store! (pointer (x), zero (UInt))
66- @test ThreadingUtilities. _atomic_xchg! (pointer (x), ThreadingUtilities. WAIT) == ThreadingUtilities. TASK
67- @test ThreadingUtilities. _atomic_umax! (pointer (x), ThreadingUtilities. TASK) == ThreadingUtilities. WAIT
68- @test ThreadingUtilities. _atomic_umax! (pointer (x), ThreadingUtilities. SPIN) == ThreadingUtilities. WAIT
69- @test ThreadingUtilities. load (pointer (x), ThreadingUtilities. ThreadState) == ThreadingUtilities. SPIN
71+ @test ThreadingUtilities. _atomic_xchg! (pointer (x), ThreadingUtilities. WAIT) ==
72+ ThreadingUtilities. TASK
73+ @test ThreadingUtilities. _atomic_umax! (pointer (x), ThreadingUtilities. TASK) ==
74+ ThreadingUtilities. WAIT
75+ @test ThreadingUtilities. _atomic_umax! (pointer (x), ThreadingUtilities. SPIN) ==
76+ ThreadingUtilities. WAIT
77+ @test ThreadingUtilities. load (pointer (x), ThreadingUtilities. ThreadState) ==
78+ ThreadingUtilities. SPIN
7079 end
7180 for tid ∈ eachindex (ThreadingUtilities. TASKS)
7281 launch_thread_copy! (tid, Float64[], Float64[])
7382 end
74- yield ( )
83+ sleep ( 1 )
7584 @test all (istaskfailed, ThreadingUtilities. TASKS)
7685 @test all (ThreadingUtilities. wait, eachindex (ThreadingUtilities. TASKS))
7786 @test ! any (istaskfailed, ThreadingUtilities. TASKS)
0 commit comments