fix: threads don't idle while inactive
This commit is contained in:
parent
a214291c2f
commit
0f5539ebc0
3 changed files with 58 additions and 15 deletions
|
|
@ -31,8 +31,26 @@ void Terrain::update_meshes() {
|
|||
this->dirty_meshes_lock.unlock();
|
||||
mesh->apply_new_mesh();
|
||||
}
|
||||
if (this->dirty_meshes.is_empty()) {
|
||||
set_process(false);
|
||||
}
|
||||
|
||||
void Terrain::update_threads() {
|
||||
this->workload_lock.lock();
|
||||
if (this->workload.is_empty()) {
|
||||
this->threads_stop = true;
|
||||
this->workload_lock.unlock();
|
||||
for (Thread &thread : this->threads) {
|
||||
if (thread.is_started()) {
|
||||
thread.wait_to_finish();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this->threads_stop = false;
|
||||
for (Thread &thread : this->threads) {
|
||||
if (!thread.is_started()) {
|
||||
thread.start(Terrain::generate_meshes_thread, this);
|
||||
}
|
||||
}
|
||||
this->workload_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +68,7 @@ void Terrain::_notification(int what) {
|
|||
return;
|
||||
case NOTIFICATION_PROCESS:
|
||||
update_meshes();
|
||||
update_threads();
|
||||
return;
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
this->workload_lock.lock();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue