diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2021-01-31 15:24:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-31 15:24:56 +0100 |
commit | 5525cd85c60455b0bb9716bbef0ad2ad8111d752 (patch) | |
tree | 52ff0e2d3e01dd2655feff1cf88f07e10d84aad1 /servers/physics_2d | |
parent | 02eb11450b4151b02db861b5029783e52e16c603 (diff) | |
parent | 99fe462452be44efa618e83ad9bbecd722ae6ecd (diff) |
Merge pull request #45315 from RandomShaper/modernize_thread
Modernize Thread
Diffstat (limited to 'servers/physics_2d')
-rw-r--r-- | servers/physics_2d/physics_server_2d_wrap_mt.cpp | 12 | ||||
-rw-r--r-- | servers/physics_2d/physics_server_2d_wrap_mt.h | 2 |
2 files changed, 5 insertions, 9 deletions
diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.cpp b/servers/physics_2d/physics_server_2d_wrap_mt.cpp index 15d875b3b7..897724fe6f 100644 --- a/servers/physics_2d/physics_server_2d_wrap_mt.cpp +++ b/servers/physics_2d/physics_server_2d_wrap_mt.cpp @@ -76,7 +76,7 @@ void PhysicsServer2DWrapMT::step(real_t p_step) { } void PhysicsServer2DWrapMT::sync() { - if (thread) { + if (create_thread) { if (first_frame) { first_frame = false; } else { @@ -97,7 +97,7 @@ void PhysicsServer2DWrapMT::end_sync() { void PhysicsServer2DWrapMT::init() { if (create_thread) { //OS::get_singleton()->release_rendering_thread(); - thread = Thread::create(_thread_callback, this); + thread.start(_thread_callback, this); while (!step_thread_up) { OS::get_singleton()->delay_usec(1000); } @@ -107,12 +107,9 @@ void PhysicsServer2DWrapMT::init() { } void PhysicsServer2DWrapMT::finish() { - if (thread) { + if (thread.is_started()) { command_queue.push(this, &PhysicsServer2DWrapMT::thread_exit); - Thread::wait_to_finish(thread); - memdelete(thread); - - thread = nullptr; + thread.wait_to_finish(); } else { physics_2d_server->finish(); } @@ -135,7 +132,6 @@ PhysicsServer2DWrapMT::PhysicsServer2DWrapMT(PhysicsServer2D *p_contained, bool command_queue(p_create_thread) { physics_2d_server = p_contained; create_thread = p_create_thread; - thread = nullptr; step_pending = 0; step_thread_up = false; diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.h b/servers/physics_2d/physics_server_2d_wrap_mt.h index 3c6ec877e0..fbc5b1eaa1 100644 --- a/servers/physics_2d/physics_server_2d_wrap_mt.h +++ b/servers/physics_2d/physics_server_2d_wrap_mt.h @@ -53,7 +53,7 @@ class PhysicsServer2DWrapMT : public PhysicsServer2D { Thread::ID server_thread; Thread::ID main_thread; volatile bool exit; - Thread *thread; + Thread thread; volatile bool step_thread_up; bool create_thread; |