Skip to content

Commit 54f65d9

Browse files
authored
Merge pull request #54 from touchlab/kpg/win_X86
Kpg/win x86
2 parents c482afa + 39e2b5b commit 54f65d9

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

gradle/gradle-mvn-mpp-push.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ publishing {
9797
}
9898

9999
tasks.register('publishWindows') {
100-
dependsOn 'publishMingwPublicationToMavenRepository'
100+
dependsOn 'publishMingwX86PublicationToMavenRepository'
101+
dependsOn 'publishMingwX64PublicationToMavenRepository'
101102
}
102103

103104
tasks.register('publishLinux') {

sqliter-driver/build.gradle.kts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fun configInterop(target: org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTar
1414
val main by target.compilations.getting
1515
val sqlite3 by main.cinterops.creating {
1616
includeDirs("$projectDir/src/include")
17+
// extraOpts = listOf("-mode", "sourcecode")
1718
}
1819

1920
target.compilations.forEach { kotlinNativeCompilation ->
@@ -44,7 +45,8 @@ kotlin {
4445
iosSimulatorArm64(),
4546
watchosSimulatorArm64(),
4647
tvosSimulatorArm64(),
47-
mingwX64("mingw"),
48+
mingwX64(),
49+
mingwX86(),
4850
linuxX64()
4951
)
5052

@@ -79,9 +81,19 @@ kotlin {
7981
val mingwMain = sourceSets.maybeCreate("mingwMain").apply {
8082
dependsOn(nativeCommonMain)
8183
}
84+
85+
val mingwX64Main = sourceSets.maybeCreate("mingwX64Main").apply {
86+
dependsOn(mingwMain)
87+
}
88+
89+
val mingwX86Main = sourceSets.maybeCreate("mingwX86Main").apply {
90+
dependsOn(mingwMain)
91+
}
92+
8293
knTargets.forEach { target ->
8394
when {
8495
target.name.startsWith("mingw") -> {
96+
target.compilations.getByName("main").defaultSourceSet.dependsOn(mingwMain)
8597
target.compilations.getByName("test").defaultSourceSet.dependsOn(nativeCommonTest)
8698
}
8799
target.name.startsWith("linux") -> {
File renamed without changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package co.touchlab.sqliter.concurrency
2+
3+
import kotlinx.cinterop.Arena
4+
import kotlinx.cinterop.alloc
5+
import kotlinx.cinterop.ptr
6+
import platform.posix.PTHREAD_MUTEX_RECURSIVE
7+
import platform.posix.pthread_mutex_destroy
8+
import platform.posix.pthread_mutex_init
9+
import platform.posix.pthread_mutex_lock
10+
import platform.posix.pthread_mutex_tVar
11+
import platform.posix.pthread_mutex_trylock
12+
import platform.posix.pthread_mutex_unlock
13+
import platform.posix.pthread_mutexattr_destroy
14+
import platform.posix.pthread_mutexattr_init
15+
import platform.posix.pthread_mutexattr_settype
16+
import platform.posix.pthread_mutexattr_tVar
17+
import kotlin.native.concurrent.freeze
18+
19+
/**
20+
* A simple lock.
21+
* Implementations of this class should be re-entrant.
22+
*/
23+
actual class Lock actual constructor() {
24+
private val arena = Arena()
25+
private val attr = arena.alloc<pthread_mutexattr_tVar>()
26+
private val mutex = arena.alloc<pthread_mutex_tVar>()
27+
28+
init {
29+
pthread_mutexattr_init(attr.ptr)
30+
pthread_mutexattr_settype(attr.ptr, PTHREAD_MUTEX_RECURSIVE.toInt())
31+
pthread_mutex_init(mutex.ptr, attr.ptr)
32+
freeze()
33+
}
34+
35+
actual fun lock() {
36+
pthread_mutex_lock(mutex.ptr)
37+
}
38+
39+
actual fun unlock() {
40+
pthread_mutex_unlock(mutex.ptr)
41+
}
42+
43+
actual fun tryLock(): Boolean = pthread_mutex_trylock(mutex.ptr) == 0
44+
45+
fun internalClose() {
46+
pthread_mutex_destroy(mutex.ptr)
47+
pthread_mutexattr_destroy(attr.ptr)
48+
arena.clear()
49+
}
50+
}
51+
52+
actual inline fun Lock.close() {
53+
internalClose()
54+
}

0 commit comments

Comments
 (0)