Skip to content

Commit 464a124

Browse files
committed
Lazy init native mutex in lincheck tests
1 parent 2c11bc5 commit 464a124

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

atomicfu/src/jvmTest/kotlin/kotlinx/atomicfu/locks/NativeMutexLincheckReentrantTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ class NativeMutexLincheckReentrantTest {
1919
private val counter = Counter()
2020
private val localParkers = ConcurrentHashMap<ParkingHandle, ThreadParker>()
2121

22-
private val lock = NativeMutex(
23-
park = { localParkers[ParkingSupport.currentThreadHandle()]!!.park() },
24-
unpark = { localParkers[it]!!.unpark() }
25-
)
22+
private val lock by lazy {
23+
NativeMutex(
24+
park = { localParkers[ParkingSupport.currentThreadHandle()]!!.park() },
25+
unpark = { localParkers[it]!!.unpark() }
26+
)
27+
}
2628

2729
@Test
2830
fun modelCheckingTest(): Unit = ModelCheckingOptions()

atomicfu/src/jvmTest/kotlin/kotlinx/atomicfu/locks/NativeMutexLincheckTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ class NativeMutexLincheckTest {
1919
private val counter = Counter()
2020
private val localParkers = ConcurrentHashMap<ParkingHandle, ThreadParker>()
2121

22-
private val lock = NativeMutex(
23-
park = { localParkers[ParkingSupport.currentThreadHandle()]!!.park() },
24-
unpark = { localParkers[it]!!.unpark() }
25-
)
22+
private val lock by lazy {
23+
NativeMutex(
24+
park = { localParkers[ParkingSupport.currentThreadHandle()]!!.park() },
25+
unpark = { localParkers[it]!!.unpark() }
26+
)
27+
}
2628

2729
@Test
2830
fun modelCheckingTest(): Unit = ModelCheckingOptions()

atomicfu/src/jvmTest/kotlin/kotlinx/atomicfu/locks/NativeMutexTimeoutLincheckTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ class NativeMutexTimeoutLincheckTest {
2020
private val counter = Counter()
2121
private val localParkers = ConcurrentHashMap<ParkingHandle, ThreadParker>()
2222

23-
private val lock = NativeMutex(
24-
park = { localParkers[ParkingSupport.currentThreadHandle()]!!.parkNanos(it.inWholeNanoseconds) },
25-
unpark = { localParkers[it]!!.unpark() }
26-
)
23+
private val lock by lazy {
24+
NativeMutex(
25+
park = { localParkers[ParkingSupport.currentThreadHandle()]!!.parkNanos(it.inWholeNanoseconds) },
26+
unpark = { localParkers[it]!!.unpark() }
27+
)
28+
}
2729

2830
@Test
2931
fun modelCheckingTest(): Unit = ModelCheckingOptions()

0 commit comments

Comments
 (0)