Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ setupDefaults(
jvm()
js { browser() }
wasmJs { browser() }
linuxX64()
linuxArm64()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
iosCompat()
watchosCompat()
tvosCompat()
Expand Down
3 changes: 3 additions & 0 deletions decompose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ kotlin {
val wasmJs by bundle()
val nonWeb by bundle()
val web by bundle()
val linux by bundle()

(darwin) dependsOn common
nonWeb dependsOn common
Expand All @@ -44,6 +45,8 @@ kotlin {
(js + wasmJs) dependsOn web
(iosSet + tvosSet) dependsOn itvos
(darwinSet - iosSet - tvosSet + itvos) dependsOn darwin
linux dependsOn common
linuxSet dependsOn linux

all {
languageSettings {
Expand Down
67 changes: 67 additions & 0 deletions decompose/src/linuxMain/kotlin/com/arkivanov/decompose/Lock.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.arkivanov.decompose

import kotlinx.cinterop.Arena
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.alloc
import kotlinx.cinterop.ptr
import platform.posix.PTHREAD_MUTEX_RECURSIVE
import platform.posix.pthread_mutex_destroy
import platform.posix.pthread_mutex_init
import platform.posix.pthread_mutex_lock
import platform.posix.pthread_mutex_t
import platform.posix.pthread_mutex_unlock
import platform.posix.pthread_mutexattr_destroy
import platform.posix.pthread_mutexattr_init
import platform.posix.pthread_mutexattr_settype
import platform.posix.pthread_mutexattr_t
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.ref.createCleaner

@OptIn(ExperimentalForeignApi::class)
Comment thread
arkivanov marked this conversation as resolved.
Resolved
internal actual class Lock actual constructor() {

private val arena = Arena()
private val attr = arena.alloc<pthread_mutexattr_t>()
private val mutex = arena.alloc<pthread_mutex_t>()

@Suppress("unused") // Must be stored in a property
@OptIn(ExperimentalNativeApi::class)
private val cleaner = createCleaner(Resources(arena, attr, mutex), Resources::destroy)

init {
pthread_mutexattr_init(attr.ptr)
pthread_mutexattr_settype(attr.ptr, PTHREAD_MUTEX_RECURSIVE.toInt())
pthread_mutex_init(mutex.ptr, attr.ptr)
}

actual inline fun <T> synchronizedImpl(block: () -> T): T {
lock()
try {
return block()
} finally {
unlock()
}
}

@PublishedApi
internal fun lock() {
pthread_mutex_lock(mutex.ptr)
Comment thread
arkivanov marked this conversation as resolved.
Resolved
}

@PublishedApi
internal fun unlock() {
pthread_mutex_unlock(mutex.ptr)
}

private class Resources(
private val arena: Arena,
private val attr: pthread_mutexattr_t,
private val mutex: pthread_mutex_t,
) {
fun destroy() {
pthread_mutex_destroy(mutex.ptr)
pthread_mutexattr_destroy(attr.ptr)
arena.clear()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.arkivanov.decompose.errorhandler

internal actual fun printError(exception: Exception) {
exception.printStackTrace()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.arkivanov.decompose.mainthread

internal actual fun checkMainThread() {
// No-op
}
2 changes: 1 addition & 1 deletion deps.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

decompose = "3.6.0-beta01"
kotlin = "2.3.21"
essenty = "2.6.0"
essenty = "2.7.0-alpha01"
reaktive = "2.2.0"
junit = "4.13.2"
jetbrainsCompose = "1.9.3"
Expand Down
Loading