mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-19 23:14:05 +09:00
new thread pooling strategy and test program WIP
This commit is contained in:
@@ -204,7 +204,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
||||
|
||||
|
||||
fun insertionSortLastElem(arr: ArrayList<Actor>) {
|
||||
lock(ReentrantLock()) {
|
||||
ReentrantLock().lock {
|
||||
var j = arr.lastIndex - 1
|
||||
val x = arr.last()
|
||||
while (j >= 0 && arr[j] > x) {
|
||||
@@ -215,13 +215,14 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun lock(lock: Lock, body: () -> Unit) {
|
||||
lock.lock()
|
||||
try {
|
||||
body()
|
||||
}
|
||||
finally {
|
||||
lock.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun Lock.lock(body: () -> Unit) {
|
||||
this.lock()
|
||||
try {
|
||||
body()
|
||||
}
|
||||
}
|
||||
finally {
|
||||
this.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user