diff --git a/build.gradle.kts b/build.gradle.kts index d1e1f90..a93a69e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,35 +1,99 @@ +import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.configureAllCompilationsOnAllTargets +import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.configureAllCompilersOptionsOnAllTargets import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.defineAllMultiplatformTargets import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.defineXomrkGiteaMavenRepo buildscript { - repositories { - mavenCentral() - maven("https://maven.landgrafhomyak.ru/") - } + repositories { + mavenCentral() + maven("https://maven.landgrafhomyak.ru/") + } - dependencies { - classpath("ru.landgrafhomyak.kotlin:kotlin-mpp-gradle-build-helper:v0.3k2.1.10") - } + dependencies { + classpath("ru.landgrafhomyak.kotlin:kotlin-mpp-gradle-build-helper:v0.3k2.1.10") + } } plugins { - kotlin("multiplatform") version "2.2.10" - `maven-publish` + kotlin("multiplatform") version "2.2.10" + `maven-publish` } group = "ru.landgrafhomyak.multitasking" version = "1.0-SNAPSHOT" repositories { - mavenCentral() + mavenCentral() } kotlin { - defineAllMultiplatformTargets() + explicitApi() + + jvm() + mingwX64() + linuxX64() + linuxArm64() + macosX64() + macosArm64() + js { + browser() + nodejs() + } + + + configureAllCompilersOptionsOnAllTargets { + freeCompilerArgs.addAll("-Xexpect-actual-classes") + } + + jvm().compilations.configureEach { + compileTaskProvider { + compilerOptions { + freeCompilerArgs.addAll("-Xjvm-default=all", "-Xdirect-java-actualization") + } + } + } + + sourceSets { + val commonMain by getting + val commonTest by getting + + val notJvmMain by creating { dependsOn(commonMain) } + val notJvmTest by creating { dependsOn(commonTest) } + + val multithreadPlatformMain by creating { dependsOn(commonMain) } + val multithreadPlatformTest by creating { dependsOn(commonTest) } + val singleThreadPlatformMain by creating { dependsOn(commonMain) } + val singleThreadPlatformTest by creating { dependsOn(commonTest) } + + targets.configureEach target@{ + if (this@target in setOf(this@kotlin.metadata(), this@kotlin.jvm())) + return@target + + this@target.compilations.getByName("main").defaultSourceSet.dependsOn(notJvmMain) + this@target.compilations.getByName("test").defaultSourceSet.dependsOn(notJvmTest) + } + + targets.configureEach target@{ + if (this@target == this@kotlin.metadata()) + return@target + if (this@target in setOf(this@kotlin.js())) { + this@target.compilations.getByName("main").defaultSourceSet.dependsOn(singleThreadPlatformMain) + this@target.compilations.getByName("test").defaultSourceSet.dependsOn(singleThreadPlatformTest) + } else { + this@target.compilations.getByName("main").defaultSourceSet.dependsOn(multithreadPlatformMain) + this@target.compilations.getByName("test").defaultSourceSet.dependsOn(multithreadPlatformTest) + } + + } + } + + + + } publishing { - repositories { - defineXomrkGiteaMavenRepo() - } + repositories { + defineXomrkGiteaMavenRepo("Multitasking") + } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 5b8c2f8..c502b5a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,2 @@ -rootProject.name = "multitasking-api" +rootProject.name = "multitasking-core" diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/multitasking_0/Fiber.kt b/src/commonMain/kotlin/ru/landgrafhomyak/multitasking_0/Fiber.kt new file mode 100644 index 0000000..8c2a42a --- /dev/null +++ b/src/commonMain/kotlin/ru/landgrafhomyak/multitasking_0/Fiber.kt @@ -0,0 +1,31 @@ +package ru.landgrafhomyak.multitasking_0 + +/** + * Handle of concurrency primitive with call stack saving. + */ +public interface Fiber { + /** + * Returns [thread][Thread] to which fiber is bound if there are restrictions to threads where fiber can be [resumed][Fiber.resume]. + */ + public val ownerThread: Thread? + + /** + * Returns `true` if this fiber running by any thread currently. Threadsafe getter. + */ + public val isRunning: Boolean /*get() = this.runningOnThread != null*/ + /*public val runningOnThread: Thread?*/ + + /** + * Switches execution flow back to thread or fiber called [resume()][Fiber.resume] to run this fiber. + * + * Must be called only inside fiber represented by this object. + */ + public fun yield() + + /** + * Switches execution flow of **current** [thread][Thread] or [fiber][Fiber] to this fiber until it's [return control back][Fiber.yield]. + * + * If fiber [bound to any thread][Fiber.ownerThread], switching must be done only inside this thread or fibers running in this thread. + */ + public fun resume() +} \ No newline at end of file diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/multitasking_0/Thread.kt b/src/commonMain/kotlin/ru/landgrafhomyak/multitasking_0/Thread.kt new file mode 100644 index 0000000..a83282e --- /dev/null +++ b/src/commonMain/kotlin/ru/landgrafhomyak/multitasking_0/Thread.kt @@ -0,0 +1,12 @@ +package ru.landgrafhomyak.multitasking_0 + +public expect class Thread { + public val name: String + override fun toString(): String + + public var runningFiber: Fiber? + + public companion object { + public fun getCurrentThread(): Thread + } +} \ No newline at end of file