File tree 2 files changed +32
-27
lines changed
2 files changed +32
-27
lines changed Original file line number Diff line number Diff line change @@ -5,34 +5,37 @@ export ThreadSafe
5
5
abstract type ThreadSafe{T} end
6
6
7
7
8
-
9
8
export ThreadSafeReentrantLock
10
9
11
- struct ThreadSafeReentrantLock
12
- thread_lock:: RecursiveSpinLock
13
- task_lock:: ReentrantLock
10
+ @static if VERSION >= v " 1.2-DEV.28"
11
+ const ThreadSafeReentrantLock = ReentrantLock
12
+ else
13
+ struct ThreadSafeReentrantLock
14
+ thread_lock:: RecursiveSpinLock
15
+ task_lock:: ReentrantLock
14
16
15
- ThreadSafeReentrantLock () = new (RecursiveSpinLock (), ReentrantLock ())
16
- end
17
+ ThreadSafeReentrantLock () = new (RecursiveSpinLock (), ReentrantLock ())
18
+ end
17
19
18
- function Base. lock (l:: ThreadSafeReentrantLock )
19
- # @debug "LOCKING $l"
20
- lock (l. thread_lock)
21
- try
22
- lock (l. task_lock)
23
- catch err
24
- unlock (l. thread_lock)
25
- rethrow ()
20
+ function Base. lock (l:: ThreadSafeReentrantLock )
21
+ # @debug "LOCKING $l"
22
+ lock (l. thread_lock)
23
+ try
24
+ lock (l. task_lock)
25
+ catch err
26
+ unlock (l. thread_lock)
27
+ rethrow ()
28
+ end
26
29
end
27
- end
28
30
29
31
30
- function Base. unlock (l:: ThreadSafeReentrantLock )
31
- # @debug "UNLOCKING $l"
32
- try
33
- unlock (l. task_lock)
34
- finally
35
- unlock (l. thread_lock)
32
+ function Base. unlock (l:: ThreadSafeReentrantLock )
33
+ # @debug "UNLOCKING $l"
34
+ try
35
+ unlock (l. task_lock)
36
+ finally
37
+ unlock (l. thread_lock)
38
+ end
36
39
end
37
40
end
38
41
Original file line number Diff line number Diff line change @@ -9,12 +9,14 @@ using Base.Threads
9
9
10
10
@testset " ThreadSafeReentrantLock" begin
11
11
tsReLock = @inferred ThreadSafeReentrantLock ()
12
- lock (tsReLock)
13
- @test islocked (tsReLock. thread_lock)
14
- @test islocked (tsReLock. task_lock)
15
- unlock (tsReLock)
16
- @test ! islocked (tsReLock. thread_lock)
17
- @test ! islocked (tsReLock. task_lock)
12
+ @static if VERSION < v " 1.2-DEV.28"
13
+ lock (tsReLock)
14
+ @test islocked (tsReLock. thread_lock)
15
+ @test islocked (tsReLock. task_lock)
16
+ unlock (tsReLock)
17
+ @test ! islocked (tsReLock. thread_lock)
18
+ @test ! islocked (tsReLock. task_lock)
19
+ end
18
20
end
19
21
20
22
@testset " LockableValue" begin
You can’t perform that action at this time.
0 commit comments