diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2020-03-03 09:26:42 +0100 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2020-03-03 13:20:42 +0100 |
commit | 9a3a2b03b8b718409eb26252d742d48091756ef7 (patch) | |
tree | 94cc5ae822288ec8b1e098773338498f865b5b77 /servers/physics_2d | |
parent | c9768f15f7bb194622b9020ab2614d47ac7e63dd (diff) |
Drop old semaphore implementation
- Removed platform-specific implementations.
- Now all semaphores are in-object, unless they need to be conditionally created.
- Similarly to `Mutex`, provided a dummy implementation for when `NO_THREADS` is defined.
- Similarly to `Mutex`, methods are made `const` for easy use in such contexts.
- Language bindings updated: `wait()` and `post()` are now `void`.
- Language bindings updated: `try_wait()` added.
Bonus:
- Rewritten the `#ifdef` in `mutex.h` to meet the code style.
Diffstat (limited to 'servers/physics_2d')
-rw-r--r-- | servers/physics_2d/physics_2d_server_wrap_mt.cpp | 15 | ||||
-rw-r--r-- | servers/physics_2d/physics_2d_server_wrap_mt.h | 2 |
2 files changed, 5 insertions, 12 deletions
diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.cpp b/servers/physics_2d/physics_2d_server_wrap_mt.cpp index 7070902f77..76036930c6 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.cpp +++ b/servers/physics_2d/physics_2d_server_wrap_mt.cpp @@ -40,7 +40,7 @@ void Physics2DServerWrapMT::thread_exit() { void Physics2DServerWrapMT::thread_step(real_t p_delta) { physics_2d_server->step(p_delta); - step_sem->post(); + step_sem.post(); } void Physics2DServerWrapMT::_thread_callback(void *_instance) { @@ -84,11 +84,11 @@ void Physics2DServerWrapMT::step(real_t p_step) { void Physics2DServerWrapMT::sync() { - if (step_sem) { + if (thread) { if (first_frame) first_frame = false; else - step_sem->wait(); //must not wait if a step was not issued + step_sem.wait(); //must not wait if a step was not issued } physics_2d_server->sync(); } @@ -107,11 +107,8 @@ void Physics2DServerWrapMT::init() { if (create_thread) { - step_sem = SemaphoreOld::create(); //OS::get_singleton()->release_rendering_thread(); - if (create_thread) { - thread = Thread::create(_thread_callback, this); - } + thread = Thread::create(_thread_callback, this); while (!step_thread_up) { OS::get_singleton()->delay_usec(1000); } @@ -146,9 +143,6 @@ void Physics2DServerWrapMT::finish() { space_free_cached_ids(); area_free_cached_ids(); body_free_cached_ids(); - - if (step_sem) - memdelete(step_sem); } Physics2DServerWrapMT::Physics2DServerWrapMT(Physics2DServer *p_contained, bool p_create_thread) : @@ -157,7 +151,6 @@ Physics2DServerWrapMT::Physics2DServerWrapMT(Physics2DServer *p_contained, bool physics_2d_server = p_contained; create_thread = p_create_thread; thread = NULL; - step_sem = NULL; step_pending = 0; step_thread_up = false; diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h index 0648b8651f..4d5e317c8c 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.h +++ b/servers/physics_2d/physics_2d_server_wrap_mt.h @@ -58,7 +58,7 @@ class Physics2DServerWrapMT : public Physics2DServer { volatile bool step_thread_up; bool create_thread; - SemaphoreOld *step_sem; + Semaphore step_sem; int step_pending; void thread_step(real_t p_delta); void thread_flush(); |