Skip to content

Commit 42d9495

Browse files
committed
Comments
1 parent a88e151 commit 42d9495

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

atomicfu/src/commonMain/kotlin/kotlinx/atomicfu/locks/SynchronousMutex.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ expect class SynchronousMutex() {
3737
* lock acquisition.
3838
*/
3939
fun tryLock(): Boolean
40-
40+
41+
/**
42+
* Tries to lock this mutex within the given [timeout] period,
43+
* returning `false` if the duration passed without locking.
44+
*
45+
* Note: when [tryLock] succeeds the lock needs to be released by [unlock].
46+
* When [tryLock] does not succeed the lock does not have to be released.
47+
*/
4148
fun tryLock(timeout: Duration): Boolean
4249

4350
/**

atomicfu/src/concurrentMain/kotlin/kotlinx/atomicfu/locks/Mutex.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import kotlinx.atomicfu.atomic
55
import kotlin.time.Duration
66
import kotlin.time.TimeSource
77

8+
/**
9+
* Mutex implementation for Kotlin/Native.
10+
* In concurrentMain sourceSet to be testable with Lincheck.
11+
* [park] and [unpark] functions can be passed for testability.
12+
*/
813
internal class NativeMutex(
914
val park : (Duration) -> Unit = { ParkingSupport.park(it) },
1015
val unpark : (ParkingHandle) -> Unit = ParkingSupport::unpark,
1116
) {
1217
/**
13-
* Mutex implementation for Kotlin/Native.
14-
* In concurrentMain sourceSet to be testable with Lincheck.
15-
*
1618
* The [state] variable stands for: 0 -> Lock is free
1719
* 1 -> Lock is locked but no waiters
1820
* 4 -> Lock is locked with 3 waiters

0 commit comments

Comments
 (0)