Now ThreadPool should properly handle when use_threads changes.

This commit is contained in:
Relintai 2022-09-10 04:34:36 +02:00
parent b6624bf30b
commit 7dd2bce61b
2 changed files with 7 additions and 1 deletions

View File

@ -40,7 +40,8 @@ bool ThreadPool::get_use_threads() const {
return _use_threads; return _use_threads;
} }
void ThreadPool::set_use_threads(const bool value) { void ThreadPool::set_use_threads(const bool value) {
_use_threads = value; // Will be applied later in update, so current jobs can be finished first
_use_threads_new = value;
_dirty = true; _dirty = true;
} }
@ -295,6 +296,8 @@ void ThreadPool::register_core_settings() {
} }
} }
_use_threads_new = _use_threads;
_dirty = true; _dirty = true;
apply_settings(); apply_settings();
@ -329,6 +332,8 @@ void ThreadPool::apply_settings() {
_threads.resize(0); _threads.resize(0);
_use_threads = _use_threads_new;
if (_use_threads) { if (_use_threads) {
_threads.resize(_thread_count); _threads.resize(_thread_count);

View File

@ -101,6 +101,7 @@ private:
bool _dirty; bool _dirty;
bool _use_threads; bool _use_threads;
bool _use_threads_new;
int _thread_count; int _thread_count;
int _thread_fallback_count; int _thread_fallback_count;
float _max_work_per_frame_percent; float _max_work_per_frame_percent;