wip fixing multithreaded noisy image bug

decided to remove my own thread pool impl to reduce the scope of attack
This commit is contained in:
minjaesong
2019-11-08 01:34:39 +09:00
parent 86be4e4edb
commit 612b7950ed
2 changed files with 43 additions and 15 deletions

View File

@@ -1,14 +1,32 @@
package net.torvald.terrarum.concurrent
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.math.absoluteValue
typealias RunnableFun = () -> Unit
/** Int: index of the processing core */
typealias ThreadableFun = (Int) -> Unit
object ThreadExecutor {
val threadCount = Runtime.getRuntime().availableProcessors() // not using (logicalCores + 1) method; it's often better idea to reserve one extra thread for other jobs in the app
private val executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
fun submit(t: Runnable) = executor.submit(t)
fun submit(f: RunnableFun) = executor.submit { f() }
fun join() {
executor.awaitTermination(24L, TimeUnit.HOURS)
}
}
/**
* Created by minjaesong on 2016-05-25.
*/
@Deprecated("Hooey implementation", ReplaceWith("ThreadExecutor", "net.torvald.terrarum.concurrent.ThreadExecutor"))
object ThreadParallel {
val threadCount = Runtime.getRuntime().availableProcessors() // not using (logicalCores + 1) method; it's often better idea to reserve one extra thread for other jobs in the app