File tree Expand file tree Collapse file tree 2 files changed +6
-8
lines changed
commonMain/kotlin/kotlinx/atomicfu/locks
jvmMain/kotlin/kotlinx/atomicfu/locks Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ expect class SynchronousMutex() {
35
35
* It is recommended to use [withLock] for safety reasons, so that the acquired lock is always
36
36
* released at the end of your critical section, and [unlock] is never invoked before a successful
37
37
* lock acquisition.
38
+ *
39
+ * (JVM only) this call can potentially skip line.
38
40
*/
39
41
fun tryLock (): Boolean
40
42
@@ -44,6 +46,8 @@ expect class SynchronousMutex() {
44
46
*
45
47
* Note: when [tryLock] succeeds the lock needs to be released by [unlock].
46
48
* When [tryLock] does not succeed the lock does not have to be released.
49
+ *
50
+ * (JVM only) throws Interrupted exception when thread is interrupted while waiting for lock.
47
51
*/
48
52
fun tryLock (timeout : Duration ): Boolean
49
53
Original file line number Diff line number Diff line change @@ -6,18 +6,12 @@ import kotlin.time.Duration
6
6
/* *
7
7
* This mutex uses a [ReentrantLock].
8
8
*
9
- * [getReentrantLock] obtains the actual [ReentrantLock].
10
9
* Construct with `Mutex(reentrantLock)` to create a [SynchronousMutex] that uses an existing instance of [ReentrantLock].
11
10
*/
12
- actual class SynchronousMutex ( private val reentrantLock : java.util.concurrent.locks. ReentrantLock ) {
13
- actual constructor () : this ( ReentrantLock () )
11
+ actual class SynchronousMutex {
12
+ private val reentrantLock = ReentrantLock ()
14
13
actual fun tryLock (timeout : Duration ): Boolean = reentrantLock.tryLock(timeout.inWholeNanoseconds, TimeUnit .NANOSECONDS )
15
14
actual fun tryLock (): Boolean = reentrantLock.tryLock()
16
15
actual fun lock () = reentrantLock.lock()
17
16
actual fun unlock () = reentrantLock.unlock()
18
-
19
- /* *
20
- * @return the underlying [ReentrantLock]
21
- */
22
- fun getReentrantLock (): ReentrantLock = reentrantLock
23
17
}
You can’t perform that action at this time.
0 commit comments