-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ReentrantLock expect class should declare a default constructor (#411)
Fixes #401
- Loading branch information
1 parent
387c3db
commit b19c23f
Showing
5 changed files
with
37 additions
and
12 deletions.
There are no files selected for viewing
8 changes: 6 additions & 2 deletions
8
atomicfu/src/commonMain/kotlin/kotlinx/atomicfu/locks/Synchronized.common.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
/* | ||
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.atomicfu.locks | ||
|
||
public expect open class SynchronizedObject() // marker abstract class | ||
|
||
public expect fun reentrantLock(): ReentrantLock | ||
|
||
public expect class ReentrantLock { | ||
public expect class ReentrantLock() { | ||
fun lock(): Unit | ||
fun tryLock(): Boolean | ||
fun unlock(): Unit | ||
} | ||
|
||
public expect inline fun <T> ReentrantLock.withLock(block: () -> T): T | ||
|
||
public expect inline fun <T> synchronized(lock: SynchronizedObject, block: () -> T): T | ||
public expect inline fun <T> synchronized(lock: SynchronizedObject, block: () -> T): T |
15 changes: 12 additions & 3 deletions
15
atomicfu/src/commonTest/kotlin/bytecode_test/ReentrantLockTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
/* | ||
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package bytecode_test | ||
|
||
import kotlinx.atomicfu.locks.* | ||
import kotlin.test.* | ||
|
||
class ReentrantLockTest { | ||
private val lock = reentrantLock() | ||
private val lock_constructor = ReentrantLock() | ||
private val lock_factory = reentrantLock() | ||
private var state = 0 | ||
|
||
@Test | ||
fun testLockField() { | ||
lock.withLock { | ||
lock_constructor.withLock { | ||
state = 6 | ||
} | ||
assertEquals(6, state) | ||
lock_factory.withLock { | ||
state = 1 | ||
} | ||
assertEquals(1, state) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
integration-testing/examples/user-project/src/commonMain/kotlin/Sample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
/* | ||
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import examples.mpp_sample.* | ||
import kotlin.test.* | ||
|
||
fun doWorld() { | ||
val sampleClass = AtomicSampleClass() | ||
sampleClass.doWork(1234) | ||
assertEquals(1234, sampleClass.x) | ||
assertEquals(42, sampleClass.synchronizedFoo(42)) | ||
assertEquals(42, sampleClass.synchronizedSetState(42)) | ||
} |