From 74e5d170d23441c6a070d8d89a0f2e85250dcbd2 Mon Sep 17 00:00:00 2001 From: Kevin Galligan Date: Sun, 14 Feb 2021 11:12:07 -0500 Subject: [PATCH 1/6] Show mac platform OK --- build.gradle | 1 + .../kotlin/co/touchlab/testhelp/concurrency/sleep.kt | 8 ++------ .../kotlin/co/touchlab/testhelp/concurrency/sleep.kt | 4 ---- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 242bc33..8109cbc 100644 --- a/build.gradle +++ b/build.gradle @@ -109,6 +109,7 @@ kotlin { nativeDarwinTest { dependsOn nativeCommonTest } + macosX64Main { dependsOn nativeDarwinMain } diff --git a/src/nativeDarwinMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt b/src/nativeDarwinMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt index a593b22..d797147 100644 --- a/src/nativeDarwinMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt +++ b/src/nativeDarwinMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt @@ -1,11 +1,7 @@ package co.touchlab.testhelp.concurrency -// import platform.posix.usleep +import platform.posix.usleep actual fun sleep(time: Long) { - val start = currentTimeMillis() - - while ((currentTimeMillis() - start) < time) { - } - // usleep((time * 1000).toUInt()) // this takes microseconds, so multiply by 1000 to use miliseconds. + usleep((time * 1000).toUInt()) // this takes microseconds, so multiply by 1000 to use miliseconds. } diff --git a/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt b/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt index a593b22..2bf18b2 100644 --- a/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt +++ b/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt @@ -3,9 +3,5 @@ package co.touchlab.testhelp.concurrency // import platform.posix.usleep actual fun sleep(time: Long) { - val start = currentTimeMillis() - - while ((currentTimeMillis() - start) < time) { - } // usleep((time * 1000).toUInt()) // this takes microseconds, so multiply by 1000 to use miliseconds. } From ab698b8526115e84b2e8155158b8522ca7c16093 Mon Sep 17 00:00:00 2001 From: Kevin Galligan Date: Sun, 14 Feb 2021 11:14:46 -0500 Subject: [PATCH 2/6] add linux --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 150b4f1..82d704f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: build: strategy: matrix: - os: [macOS-latest, windows-latest] + os: [macOS-latest, ubuntu-latest, windows-latest] runs-on: ${{matrix.os}} steps: - name: Checkout the repo From c90e669326c3c56ad9db527f3e9e15ceda3364c5 Mon Sep 17 00:00:00 2001 From: Kevin Galligan Date: Sun, 14 Feb 2021 11:34:09 -0500 Subject: [PATCH 3/6] remove mac build --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 82d704f..900b85c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: build: strategy: matrix: - os: [macOS-latest, ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest] runs-on: ${{matrix.os}} steps: - name: Checkout the repo From df69b24057bb96e9fb17f458b208dfa65d4f88b5 Mon Sep 17 00:00:00 2001 From: Kevin Galligan Date: Sun, 14 Feb 2021 11:40:42 -0500 Subject: [PATCH 4/6] Run linux --- .../kotlin/co/touchlab/testhelp/concurrency/sleep.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt b/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt index 2bf18b2..d797147 100644 --- a/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt +++ b/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt @@ -1,7 +1,7 @@ package co.touchlab.testhelp.concurrency -// import platform.posix.usleep +import platform.posix.usleep actual fun sleep(time: Long) { - // usleep((time * 1000).toUInt()) // this takes microseconds, so multiply by 1000 to use miliseconds. + usleep((time * 1000).toUInt()) // this takes microseconds, so multiply by 1000 to use miliseconds. } From 9eb990d74c253193b13cfca01495625dc7a5afe5 Mon Sep 17 00:00:00 2001 From: Kevin Galligan Date: Sun, 14 Feb 2021 12:04:24 -0500 Subject: [PATCH 5/6] Try flat layout --- .github/workflows/build.yml | 2 +- build.gradle | 20 +++++-------- .../kotlin/co/touchlab/testhelp/Functions.kt | 10 +++++++ .../testhelp/concurrency/ThreadOperations.kt | 28 +++++++++++++++++++ .../kotlin/co/touchlab/testhelp/Functions.kt | 10 +++++++ .../testhelp/concurrency/ThreadOperations.kt | 28 +++++++++++++++++++ .../kotlin/co/touchlab/testhelp/Functions.kt | 10 +++++++ .../testhelp/concurrency/ThreadOperations.kt | 28 +++++++++++++++++++ 8 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 src/nativeDarwinMain/kotlin/co/touchlab/testhelp/Functions.kt create mode 100644 src/nativeDarwinMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt create mode 100644 src/nativeLinuxMain/kotlin/co/touchlab/testhelp/Functions.kt create mode 100644 src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt create mode 100644 src/nativeMingwMain/kotlin/co/touchlab/testhelp/Functions.kt create mode 100644 src/nativeMingwMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 900b85c..82d704f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: build: strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [macOS-latest, ubuntu-latest, windows-latest] runs-on: ${{matrix.os}} steps: - name: Checkout the repo diff --git a/build.gradle b/build.gradle index 8109cbc..ab0f019 100644 --- a/build.gradle +++ b/build.gradle @@ -97,17 +97,11 @@ kotlin { } } - nativeCommonMain { - dependsOn commonMain - } - nativeCommonTest { - dependsOn commonTest - } nativeDarwinMain { - dependsOn nativeCommonMain + dependsOn commonMain } nativeDarwinTest { - dependsOn nativeCommonTest + dependsOn commonTest } macosX64Main { @@ -142,21 +136,21 @@ kotlin { } nativeMingwMain { - dependsOn nativeCommonMain + dependsOn commonMain } nativeMingwTest { - dependsOn nativeCommonTest + dependsOn commonTest } mingwX64Main { - dependsOn nativeMingwMain + dependsOn commonMain } nativeLinuxMain { - dependsOn nativeCommonMain + dependsOn commonMain } nativeLinuxTest { - dependsOn nativeCommonTest + dependsOn commonTest } linuxX64Main { diff --git a/src/nativeDarwinMain/kotlin/co/touchlab/testhelp/Functions.kt b/src/nativeDarwinMain/kotlin/co/touchlab/testhelp/Functions.kt new file mode 100644 index 0000000..224d20f --- /dev/null +++ b/src/nativeDarwinMain/kotlin/co/touchlab/testhelp/Functions.kt @@ -0,0 +1,10 @@ +package co.touchlab.testhelp + +import kotlin.native.concurrent.freeze +import kotlin.native.concurrent.isFrozen + +actual fun T.freeze(): T = this.freeze() +actual val isNative: Boolean = true +actual val isMultithreaded: Boolean = true +actual val T.isFrozen: Boolean + get() = this.isFrozen diff --git a/src/nativeDarwinMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt b/src/nativeDarwinMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt new file mode 100644 index 0000000..b12099e --- /dev/null +++ b/src/nativeDarwinMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt @@ -0,0 +1,28 @@ +package co.touchlab.testhelp.concurrency + +import kotlin.native.concurrent.Future +import kotlin.native.concurrent.TransferMode +import kotlin.native.concurrent.Worker +import kotlin.native.concurrent.freeze +import kotlin.system.getTimeMillis + +actual class MPWorker actual constructor() { + val worker = Worker.start() + actual fun runBackground(backJob: () -> T): MPFuture { + return MPFuture( + worker.execute(TransferMode.SAFE, { backJob.freeze() }) { + it() + } + ) + } + + actual fun requestTermination() { + worker.requestTermination().result + } +} + +actual class MPFuture(private val future: Future) { + actual fun consume(): T = future.result +} + +actual fun currentTimeMillis(): Long = getTimeMillis() diff --git a/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/Functions.kt b/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/Functions.kt new file mode 100644 index 0000000..224d20f --- /dev/null +++ b/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/Functions.kt @@ -0,0 +1,10 @@ +package co.touchlab.testhelp + +import kotlin.native.concurrent.freeze +import kotlin.native.concurrent.isFrozen + +actual fun T.freeze(): T = this.freeze() +actual val isNative: Boolean = true +actual val isMultithreaded: Boolean = true +actual val T.isFrozen: Boolean + get() = this.isFrozen diff --git a/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt b/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt new file mode 100644 index 0000000..b12099e --- /dev/null +++ b/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt @@ -0,0 +1,28 @@ +package co.touchlab.testhelp.concurrency + +import kotlin.native.concurrent.Future +import kotlin.native.concurrent.TransferMode +import kotlin.native.concurrent.Worker +import kotlin.native.concurrent.freeze +import kotlin.system.getTimeMillis + +actual class MPWorker actual constructor() { + val worker = Worker.start() + actual fun runBackground(backJob: () -> T): MPFuture { + return MPFuture( + worker.execute(TransferMode.SAFE, { backJob.freeze() }) { + it() + } + ) + } + + actual fun requestTermination() { + worker.requestTermination().result + } +} + +actual class MPFuture(private val future: Future) { + actual fun consume(): T = future.result +} + +actual fun currentTimeMillis(): Long = getTimeMillis() diff --git a/src/nativeMingwMain/kotlin/co/touchlab/testhelp/Functions.kt b/src/nativeMingwMain/kotlin/co/touchlab/testhelp/Functions.kt new file mode 100644 index 0000000..224d20f --- /dev/null +++ b/src/nativeMingwMain/kotlin/co/touchlab/testhelp/Functions.kt @@ -0,0 +1,10 @@ +package co.touchlab.testhelp + +import kotlin.native.concurrent.freeze +import kotlin.native.concurrent.isFrozen + +actual fun T.freeze(): T = this.freeze() +actual val isNative: Boolean = true +actual val isMultithreaded: Boolean = true +actual val T.isFrozen: Boolean + get() = this.isFrozen diff --git a/src/nativeMingwMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt b/src/nativeMingwMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt new file mode 100644 index 0000000..b12099e --- /dev/null +++ b/src/nativeMingwMain/kotlin/co/touchlab/testhelp/concurrency/ThreadOperations.kt @@ -0,0 +1,28 @@ +package co.touchlab.testhelp.concurrency + +import kotlin.native.concurrent.Future +import kotlin.native.concurrent.TransferMode +import kotlin.native.concurrent.Worker +import kotlin.native.concurrent.freeze +import kotlin.system.getTimeMillis + +actual class MPWorker actual constructor() { + val worker = Worker.start() + actual fun runBackground(backJob: () -> T): MPFuture { + return MPFuture( + worker.execute(TransferMode.SAFE, { backJob.freeze() }) { + it() + } + ) + } + + actual fun requestTermination() { + worker.requestTermination().result + } +} + +actual class MPFuture(private val future: Future) { + actual fun consume(): T = future.result +} + +actual fun currentTimeMillis(): Long = getTimeMillis() From 6165281d5b1e731a001470065eb50c85dec581eb Mon Sep 17 00:00:00 2001 From: Kevin Galligan Date: Sun, 14 Feb 2021 12:07:38 -0500 Subject: [PATCH 6/6] Just mac maybe --- .../kotlin/co/touchlab/testhelp/concurrency/sleep.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt b/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt index d797147..2bf18b2 100644 --- a/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt +++ b/src/nativeLinuxMain/kotlin/co/touchlab/testhelp/concurrency/sleep.kt @@ -1,7 +1,7 @@ package co.touchlab.testhelp.concurrency -import platform.posix.usleep +// import platform.posix.usleep actual fun sleep(time: Long) { - usleep((time * 1000).toUInt()) // this takes microseconds, so multiply by 1000 to use miliseconds. + // usleep((time * 1000).toUInt()) // this takes microseconds, so multiply by 1000 to use miliseconds. }