<lambda>null1 package kotlinx.atomicfu.test
2 
3 import kotlinx.atomicfu.*
4 import kotlin.test.Test
5 import kotlin.test.assertEquals
6 
7 class InlineCASTest {
8 
9     private val a = atomic(0)
10     private val ref = atomic(listOf("AAA"))
11 
12     @Suppress("NOTHING_TO_INLINE")
13     private inline fun AtomicInt.casLoop(to: Int): Int = loop { cur ->
14         if (compareAndSet(cur, to)) return value
15     }
16 
17     @Suppress("NOTHING_TO_INLINE")
18     private inline fun AtomicRef<List<String>>.casLoop(to: List<String>): List<String> = loop { cur ->
19         if (compareAndSet(cur, to)) return value
20     }
21 
22     @Test
23     fun testLocalVariableScope() {
24         assertEquals(a.casLoop(5), 5)
25         assertEquals(ref.casLoop(listOf("BBB")), listOf("BBB"))
26     }
27 }