mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
TilePropCodex is now object, torch flicker (WIP as all the torches are in unison)
Former-commit-id: df9c0e3a9ace2ba976da5e81f1f2d2217db541a0 Former-commit-id: 81a25a938023f318937e1f4ded15e6047fdf8864
This commit is contained in:
@@ -7,15 +7,17 @@ import java.util.*
|
||||
* Created by minjaesong on 16-05-25.
|
||||
*/
|
||||
object ThreadPool {
|
||||
private val pool = Array<Thread>(Terrarum.CORES, { Thread() })
|
||||
val POOL_SIZE = Terrarum.CORES
|
||||
val POOL_SIZE = Terrarum.CORES + 1
|
||||
|
||||
private val pool: Array<Thread?> = Array(POOL_SIZE, { null })
|
||||
|
||||
/**
|
||||
* Map array of Runnable objects to thread pool.
|
||||
* @param prefix : will name each thread as "Foo-1"
|
||||
* @param runnables : vararg
|
||||
*/
|
||||
fun mapAll(prefix: String, vararg runnables: Runnable) {
|
||||
if (runnables.size != Terrarum.CORES)
|
||||
fun mapAll(prefix: String, runnables: Array<Runnable>) {
|
||||
if (runnables.size != POOL_SIZE)
|
||||
throw RuntimeException("Thread pool argument size mismatch. If you have four cores, you must use four runnables.")
|
||||
|
||||
for (i in 0..runnables.size)
|
||||
@@ -23,6 +25,7 @@ object ThreadPool {
|
||||
}
|
||||
|
||||
/**
|
||||
* Map Runnable object to certain index of the thread pool.
|
||||
* @param index of the runnable
|
||||
* @param runnable
|
||||
* @param prefix Will name each thread like "Foo-1", "Foo-2", etc.
|
||||
@@ -31,7 +34,18 @@ object ThreadPool {
|
||||
pool[index] = Thread(runnable, "$prefix-$index")
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the thread pool with NULL value.
|
||||
*/
|
||||
fun purge() {
|
||||
for (i in 0..POOL_SIZE)
|
||||
pool[i] = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Start all thread in the pool. If the thread in the pool is NULL, it will simply ignored.
|
||||
*/
|
||||
fun startAll() {
|
||||
pool.forEach { it.start() }
|
||||
pool.forEach { it?.start() }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user