Skip to content

Commit

Permalink
Merge pull request #54 from touchlab/kpg/win_X86
Browse files Browse the repository at this point in the history
Kpg/win x86
  • Loading branch information
kpgalligan authored Sep 1, 2021
2 parents c482afa + 39e2b5b commit 54f65d9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
3 changes: 2 additions & 1 deletion gradle/gradle-mvn-mpp-push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ publishing {
}

tasks.register('publishWindows') {
dependsOn 'publishMingwPublicationToMavenRepository'
dependsOn 'publishMingwX86PublicationToMavenRepository'
dependsOn 'publishMingwX64PublicationToMavenRepository'
}

tasks.register('publishLinux') {
Expand Down
14 changes: 13 additions & 1 deletion sqliter-driver/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -44,7 +45,8 @@ kotlin {
iosSimulatorArm64(),
watchosSimulatorArm64(),
tvosSimulatorArm64(),
mingwX64("mingw"),
mingwX64(),
mingwX86(),
linuxX64()
)

Expand Down Expand Up @@ -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") -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<pthread_mutexattr_tVar>()
private val mutex = arena.alloc<pthread_mutex_tVar>()

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()
}

0 comments on commit 54f65d9

Please sign in to comment.