Skip to content

Commit e2fd88e

Browse files
committed
Revert "WorkerThreadPool: Enhance lifetime for more flexibility"
This reverts commit 2d1dd41.
1 parent d5d6c73 commit e2fd88e

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

core/object/worker_thread_pool.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,6 @@ WorkerThreadPool::TaskID WorkerThreadPool::add_native_task(void (*p_func)(void *
323323
}
324324

325325
WorkerThreadPool::TaskID WorkerThreadPool::_add_task(const Callable &p_callable, void (*p_func)(void *), void *p_userdata, BaseTemplateUserdata *p_template_userdata, bool p_high_priority, const String &p_description) {
326-
ERR_FAIL_COND_V_MSG(threads.is_empty(), INVALID_TASK_ID, "Can't add a task because the WorkerThreadPool is either not initialized yet or already terminated.");
327-
328326
task_mutex.lock();
329327
// Get a free task
330328
Task *task = task_allocator.alloc();
@@ -543,7 +541,6 @@ void WorkerThreadPool::notify_yield_over(TaskID p_task_id) {
543541
}
544542

545543
WorkerThreadPool::GroupID WorkerThreadPool::_add_group_task(const Callable &p_callable, void (*p_func)(void *, uint32_t), void *p_userdata, BaseTemplateUserdata *p_template_userdata, int p_elements, int p_tasks, bool p_high_priority, const String &p_description) {
546-
ERR_FAIL_COND_V_MSG(threads.is_empty(), INVALID_TASK_ID, "Can't add a group task because the WorkerThreadPool is either not initialized yet or already terminated.");
547544
ERR_FAIL_COND_V(p_elements < 0, INVALID_TASK_ID);
548545
if (p_tasks < 0) {
549546
p_tasks = MAX(1u, threads.size());
@@ -755,5 +752,5 @@ WorkerThreadPool::WorkerThreadPool() {
755752
}
756753

757754
WorkerThreadPool::~WorkerThreadPool() {
758-
DEV_ASSERT(threads.size() == 0 && "finish() hasn't been called!");
755+
finish();
759756
}

core/register_core_types.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ static Time *_time = nullptr;
107107
static core_bind::Geometry2D *_geometry_2d = nullptr;
108108
static core_bind::Geometry3D *_geometry_3d = nullptr;
109109

110+
static WorkerThreadPool *worker_thread_pool = nullptr;
111+
110112
extern Mutex _global_mutex;
111113

112114
static GDExtensionManager *gdextension_manager = nullptr;
@@ -295,6 +297,8 @@ void register_core_types() {
295297
GDREGISTER_NATIVE_STRUCT(AudioFrame, "float left;float right");
296298
GDREGISTER_NATIVE_STRUCT(ScriptLanguageExtensionProfilingInfo, "StringName signature;uint64_t call_count;uint64_t total_time;uint64_t self_time");
297299

300+
worker_thread_pool = memnew(WorkerThreadPool);
301+
298302
OS::get_singleton()->benchmark_end_measure("Core", "Register Types");
299303
}
300304

@@ -345,7 +349,7 @@ void register_core_singletons() {
345349
Engine::get_singleton()->add_singleton(Engine::Singleton("Time", Time::get_singleton()));
346350
Engine::get_singleton()->add_singleton(Engine::Singleton("GDExtensionManager", GDExtensionManager::get_singleton()));
347351
Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceUID", ResourceUID::get_singleton()));
348-
Engine::get_singleton()->add_singleton(Engine::Singleton("WorkerThreadPool", WorkerThreadPool::get_singleton()));
352+
Engine::get_singleton()->add_singleton(Engine::Singleton("WorkerThreadPool", worker_thread_pool));
349353

350354
OS::get_singleton()->benchmark_end_measure("Core", "Register Singletons");
351355
}
@@ -378,6 +382,8 @@ void unregister_core_types() {
378382

379383
// Destroy singletons in reverse order to ensure dependencies are not broken.
380384

385+
memdelete(worker_thread_pool);
386+
381387
memdelete(_engine_debugger);
382388
memdelete(_marshalls);
383389
memdelete(_classdb);

main/main.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ static Engine *engine = nullptr;
140140
static ProjectSettings *globals = nullptr;
141141
static Input *input = nullptr;
142142
static InputMap *input_map = nullptr;
143-
static WorkerThreadPool *worker_thread_pool = nullptr;
144143
static TranslationServer *translation_server = nullptr;
145144
static Performance *performance = nullptr;
146145
static PackedData *packed_data = nullptr;
@@ -691,8 +690,6 @@ Error Main::test_setup() {
691690

692691
register_core_settings(); // Here globals are present.
693692

694-
worker_thread_pool = memnew(WorkerThreadPool);
695-
696693
translation_server = memnew(TranslationServer);
697694
tsman = memnew(TextServerManager);
698695

@@ -803,8 +800,6 @@ void Main::test_cleanup() {
803800
ResourceSaver::remove_custom_savers();
804801
PropertyListHelper::clear_base_helpers();
805802

806-
WorkerThreadPool::get_singleton()->finish();
807-
808803
#ifdef TOOLS_ENABLED
809804
GDExtensionManager::get_singleton()->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_EDITOR);
810805
uninitialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
@@ -846,9 +841,6 @@ void Main::test_cleanup() {
846841
if (physics_server_2d_manager) {
847842
memdelete(physics_server_2d_manager);
848843
}
849-
if (worker_thread_pool) {
850-
memdelete(worker_thread_pool);
851-
}
852844
if (globals) {
853845
memdelete(globals);
854846
}
@@ -939,7 +931,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
939931

940932
register_core_settings(); //here globals are present
941933

942-
worker_thread_pool = memnew(WorkerThreadPool);
943934
translation_server = memnew(TranslationServer);
944935
performance = memnew(Performance);
945936
GDREGISTER_CLASS(Performance);
@@ -2629,10 +2620,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
26292620
if (translation_server) {
26302621
memdelete(translation_server);
26312622
}
2632-
if (worker_thread_pool) {
2633-
worker_thread_pool->finish();
2634-
memdelete(worker_thread_pool);
2635-
}
26362623
if (globals) {
26372624
memdelete(globals);
26382625
}
@@ -4514,8 +4501,6 @@ void Main::cleanup(bool p_force) {
45144501
ResourceLoader::clear_translation_remaps();
45154502
ResourceLoader::clear_path_remaps();
45164503

4517-
WorkerThreadPool::get_singleton()->finish();
4518-
45194504
ScriptServer::finish_languages();
45204505

45214506
// Sync pending commands that may have been queued from a different thread during ScriptServer finalization
@@ -4606,9 +4591,6 @@ void Main::cleanup(bool p_force) {
46064591
if (physics_server_2d_manager) {
46074592
memdelete(physics_server_2d_manager);
46084593
}
4609-
if (worker_thread_pool) {
4610-
memdelete(worker_thread_pool);
4611-
}
46124594
if (globals) {
46134595
memdelete(globals);
46144596
}

0 commit comments

Comments
 (0)