diff --git a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Thread.kt b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Thread.kt new file mode 100644 index 00000000..fb41ae07 --- /dev/null +++ b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Thread.kt @@ -0,0 +1,15 @@ +package net.dankito.utils.multiplatform + + +expect class Thread() { + + companion object { + + val current: Thread + + } + + + val threadName: String + +} \ No newline at end of file diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Thread.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Thread.kt new file mode 100644 index 00000000..211c3a01 --- /dev/null +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Thread.kt @@ -0,0 +1,33 @@ +package net.dankito.utils.multiplatform + +import platform.Foundation.NSOperationQueue +import platform.Foundation.NSThread + + +actual class Thread(private val thread: NSThread) { + + actual companion object { + + actual val current: Thread + get() = Thread(NSThread.currentThread) + + } + + + actual constructor() : this(NSThread()) + + + actual val threadName: String + get() { + thread.name?.let { name -> + if (name.isNotBlank()) { + return name + } + } + + return thread.description + ?: NSOperationQueue.currentQueue?.underlyingQueue?.description + ?: "Could not retrieve thread's name" + } + +} \ No newline at end of file diff --git a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Thread.kt b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Thread.kt new file mode 100644 index 00000000..c4e9dddc --- /dev/null +++ b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Thread.kt @@ -0,0 +1,20 @@ +package net.dankito.utils.multiplatform + + +actual class Thread(private val thread: java.lang.Thread) : java.lang.Thread() { + + actual companion object { + + actual val current: Thread + get() = Thread(currentThread()) + + } + + + actual constructor() : this(java.lang.Thread()) + + + actual val threadName: String + get() = thread.name + +} \ No newline at end of file