diff --git a/gradle/gradle-mvn-mpp-push.gradle b/gradle/gradle-mvn-mpp-push.gradle index 348c6972..7b732aee 100644 --- a/gradle/gradle-mvn-mpp-push.gradle +++ b/gradle/gradle-mvn-mpp-push.gradle @@ -97,7 +97,8 @@ publishing { } tasks.register('publishWindows') { - dependsOn 'publishMingwPublicationToMavenRepository' + dependsOn 'publishMingwX86PublicationToMavenRepository' + dependsOn 'publishMingwX64PublicationToMavenRepository' } tasks.register('publishLinux') { diff --git a/sqliter-driver/build.gradle.kts b/sqliter-driver/build.gradle.kts index ecaf5506..8338adfb 100644 --- a/sqliter-driver/build.gradle.kts +++ b/sqliter-driver/build.gradle.kts @@ -14,6 +14,7 @@ fun configInterop(target: org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTar val main by target.compilations.getting val sqlite3 by main.cinterops.creating { includeDirs("$projectDir/src/include") +// extraOpts = listOf("-mode", "sourcecode") } target.compilations.forEach { kotlinNativeCompilation -> @@ -44,7 +45,8 @@ kotlin { iosSimulatorArm64(), watchosSimulatorArm64(), tvosSimulatorArm64(), - mingwX64("mingw"), + mingwX64(), + mingwX86(), linuxX64() ) @@ -79,9 +81,19 @@ kotlin { val mingwMain = sourceSets.maybeCreate("mingwMain").apply { dependsOn(nativeCommonMain) } + + val mingwX64Main = sourceSets.maybeCreate("mingwX64Main").apply { + dependsOn(mingwMain) + } + + val mingwX86Main = sourceSets.maybeCreate("mingwX86Main").apply { + dependsOn(mingwMain) + } + knTargets.forEach { target -> when { target.name.startsWith("mingw") -> { + target.compilations.getByName("main").defaultSourceSet.dependsOn(mingwMain) target.compilations.getByName("test").defaultSourceSet.dependsOn(nativeCommonTest) } target.name.startsWith("linux") -> { diff --git a/sqliter-driver/src/mingwMain/kotlin/co/touchlab/sqliter/concurrency/Lock.kt b/sqliter-driver/src/mingwX64Main/kotlin/co/touchlab/sqliter/concurrency/Lock.kt similarity index 100% rename from sqliter-driver/src/mingwMain/kotlin/co/touchlab/sqliter/concurrency/Lock.kt rename to sqliter-driver/src/mingwX64Main/kotlin/co/touchlab/sqliter/concurrency/Lock.kt diff --git a/sqliter-driver/src/mingwX86Main/kotlin/co/touchlab/sqliter/concurrency/Lock.kt b/sqliter-driver/src/mingwX86Main/kotlin/co/touchlab/sqliter/concurrency/Lock.kt new file mode 100644 index 00000000..0fde0425 --- /dev/null +++ b/sqliter-driver/src/mingwX86Main/kotlin/co/touchlab/sqliter/concurrency/Lock.kt @@ -0,0 +1,54 @@ +package co.touchlab.sqliter.concurrency + +import kotlinx.cinterop.Arena +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_tVar +import platform.posix.pthread_mutex_trylock +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_tVar +import kotlin.native.concurrent.freeze + +/** + * A simple lock. + * Implementations of this class should be re-entrant. + */ +actual class Lock actual constructor() { + private val arena = Arena() + private val attr = arena.alloc() + private val mutex = arena.alloc() + + init { + pthread_mutexattr_init(attr.ptr) + pthread_mutexattr_settype(attr.ptr, PTHREAD_MUTEX_RECURSIVE.toInt()) + pthread_mutex_init(mutex.ptr, attr.ptr) + freeze() + } + + actual fun lock() { + pthread_mutex_lock(mutex.ptr) + } + + actual fun unlock() { + pthread_mutex_unlock(mutex.ptr) + } + + actual fun tryLock(): Boolean = pthread_mutex_trylock(mutex.ptr) == 0 + + fun internalClose() { + pthread_mutex_destroy(mutex.ptr) + pthread_mutexattr_destroy(attr.ptr) + arena.clear() + } +} + +actual inline fun Lock.close() { + internalClose() +} \ No newline at end of file