Gross stdlib cleanup (part 2) (#1924)

This commit is contained in:
Nikolay Igotti
2018-08-24 10:14:10 +03:00
committed by GitHub
parent 6d4218c3af
commit 59eae5e04b
60 changed files with 135 additions and 165 deletions
@@ -15,9 +15,10 @@
*/
import global.*
import kotlin.native.concurrent.*
import kotlinx.cinterop.*
import platform.posix.*
import kotlin.native.worker.*
inline fun Int.ensureUnixCallResult(op: String, predicate: (Int) -> Boolean = { x -> x == 0} ): Int {
if (!predicate(this)) {
@@ -49,7 +50,7 @@ fun main(args: Array<String>) {
sharedData.f = 0.5f
sharedData.string = "Hello Kotlin!".cstr.getPointer(arena)
// Here we create detached mutable object, which could be later reattached by another thread.
sharedData.kotlinObject = kotlin.native.worker.detachObjectGraph {
sharedData.kotlinObject = detachObjectGraph {
SharedData("A string", 42, SharedDataMember(2.39))
}
// Here we create shared frozen object reference,
@@ -66,12 +67,12 @@ fun main(args: Array<String>) {
argC ->
initRuntimeIfNeeded()
dumpShared("thread2")
val kotlinObject = kotlin.native.worker.attachObjectGraph<SharedData>(sharedData.kotlinObject)
val arg = kotlin.native.worker.attachObjectGraph<SharedDataMember>(argC)
val kotlinObject = attachObjectGraph<SharedData>(sharedData.kotlinObject)
val arg = attachObjectGraph<SharedDataMember>(argC)
println("thread arg is $arg Kotlin object is $kotlinObject frozen is $globalObject")
// Workaround for compiler issue.
null as COpaquePointer?
}, kotlin.native.worker.detachObjectGraph { SharedDataMember(3.14)} ).ensureUnixCallResult("pthread_create")
}, detachObjectGraph { SharedDataMember(3.14)} ).ensureUnixCallResult("pthread_create")
pthread_join(thread.value, null).ensureUnixCallResult("pthread_join")
}
+4 -2
View File
@@ -1,3 +1,5 @@
import kotlin.native.concurrent.attachObjectGraph
import kotlin.native.concurrent.detachObjectGraph
import kotlinx.cinterop.*
import platform.AppKit.*
import platform.Foundation.*
@@ -30,12 +32,12 @@ private class Controller : NSObject() {
@ObjCAction
fun onClick() {
// Execute some async action on button click.
dispatch_async_f(asyncQueue, kotlin.native.worker.detachObjectGraph {
dispatch_async_f(asyncQueue, detachObjectGraph {
Data(clock_gettime_nsec_np(CLOCK_REALTIME))
}, staticCFunction {
it ->
initRuntimeIfNeeded()
val data = kotlin.native.worker.attachObjectGraph<Data>(it)
val data = attachObjectGraph<Data>(it)
println("in async: $data")
})
}
@@ -15,8 +15,8 @@
*/
import ffmpeg.*
import kotlin.native.concurrent.*
import kotlinx.cinterop.*
import kotlin.native.worker.*
import platform.posix.memcpy
// This global variable only set to != null value in the decoding worker.
@@ -329,7 +329,7 @@ class DecoderWorker : Disposable {
// All the real state must be stored on the worker's side.
private val worker: Worker
constructor() { worker = kotlin.native.worker.startWorker() }
constructor() { worker = startWorker() }
constructor(id: WorkerId) { worker = Worker(id) }
override fun dispose() {
+1 -1
View File
@@ -1,4 +1,4 @@
import kotlin.native.worker.*
import kotlin.native.concurrent.*
data class WorkerArgument(val intParam: Int, val stringParam: String)
data class WorkerResult(val intResult: Int, val stringResult: String)