Source sets hierarchy and fiber and thread interfaces
This commit is contained in:
parent
b74cf0ad4c
commit
0f74f7f4e3
@ -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.defineAllMultiplatformTargets
|
||||||
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.defineXomrkGiteaMavenRepo
|
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.defineXomrkGiteaMavenRepo
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven("https://maven.landgrafhomyak.ru/")
|
maven("https://maven.landgrafhomyak.ru/")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath("ru.landgrafhomyak.kotlin:kotlin-mpp-gradle-build-helper:v0.3k2.1.10")
|
classpath("ru.landgrafhomyak.kotlin:kotlin-mpp-gradle-build-helper:v0.3k2.1.10")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("multiplatform") version "2.2.10"
|
kotlin("multiplatform") version "2.2.10"
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "ru.landgrafhomyak.multitasking"
|
group = "ru.landgrafhomyak.multitasking"
|
||||||
version = "1.0-SNAPSHOT"
|
version = "1.0-SNAPSHOT"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
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 {
|
publishing {
|
||||||
repositories {
|
repositories {
|
||||||
defineXomrkGiteaMavenRepo()
|
defineXomrkGiteaMavenRepo("Multitasking")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,2 +1,2 @@
|
|||||||
rootProject.name = "multitasking-api"
|
rootProject.name = "multitasking-core"
|
||||||
|
|
||||||
|
|||||||
@ -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()
|
||||||
|
}
|
||||||
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user