From f630940591f66cc98fb52f2873e8c9f1eb1ee056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Fri, 27 Jan 2023 11:04:41 +0100 Subject: [PATCH] Booleanize various sync primitives' wait & locking methods --- core/core_bind.cpp | 6 +++--- core/core_bind.h | 4 ++-- core/math/bvh.h | 2 +- core/os/mutex.h | 5 ++--- core/os/rw_lock.h | 14 ++++++-------- doc/classes/Mutex.xml | 4 ++-- doc/classes/Semaphore.xml | 4 ++-- drivers/coreaudio/audio_driver_coreaudio.cpp | 2 +- platform/android/audio_driver_opensl.cpp | 2 +- 9 files changed, 20 insertions(+), 23 deletions(-) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 96e1da9dde3..9de901754ab 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -1105,8 +1105,8 @@ void Semaphore::wait() { semaphore.wait(); } -Error Semaphore::try_wait() { - return semaphore.try_wait() ? OK : ERR_BUSY; +bool Semaphore::try_wait() { + return semaphore.try_wait(); } void Semaphore::post() { @@ -1125,7 +1125,7 @@ void Mutex::lock() { mutex.lock(); } -Error Mutex::try_lock() { +bool Mutex::try_lock() { return mutex.try_lock(); } diff --git a/core/core_bind.h b/core/core_bind.h index c0c87fd0099..88524632344 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -361,7 +361,7 @@ class Mutex : public RefCounted { public: void lock(); - Error try_lock(); + bool try_lock(); void unlock(); }; @@ -373,7 +373,7 @@ class Semaphore : public RefCounted { public: void wait(); - Error try_wait(); + bool try_wait(); void post(); }; diff --git a/core/math/bvh.h b/core/math/bvh.h index 9de704834be..9041d168ed9 100644 --- a/core/math/bvh.h +++ b/core/math/bvh.h @@ -784,7 +784,7 @@ private: if (p_thread_safe) { _mutex = p_mutex; - if (_mutex->try_lock() != OK) { + if (!_mutex->try_lock()) { WARN_PRINT("Info : multithread BVH access detected (benign)"); _mutex->lock(); } diff --git a/core/os/mutex.h b/core/os/mutex.h index c91917a9a11..ceedcb235a2 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -31,7 +31,6 @@ #ifndef MUTEX_H #define MUTEX_H -#include "core/error/error_list.h" #include "core/typedefs.h" #include @@ -49,8 +48,8 @@ public: mutex.unlock(); } - _ALWAYS_INLINE_ Error try_lock() const { - return mutex.try_lock() ? OK : ERR_BUSY; + _ALWAYS_INLINE_ bool try_lock() const { + return mutex.try_lock(); } }; diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h index e290b7c00b4..7b232600b72 100644 --- a/core/os/rw_lock.h +++ b/core/os/rw_lock.h @@ -31,8 +31,6 @@ #ifndef RW_LOCK_H #define RW_LOCK_H -#include "core/error/error_list.h" - #include class RWLock { @@ -49,9 +47,9 @@ public: mutex.unlock_shared(); } - // Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock. - Error read_try_lock() const { - return mutex.try_lock_shared() ? OK : ERR_BUSY; + // Attempt to lock the RWLock for reading. True on success, false means it can't lock. + bool read_try_lock() const { + return mutex.try_lock_shared(); } // Lock the rwlock, block if locked by someone else @@ -64,9 +62,9 @@ public: mutex.unlock(); } - // Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock. - Error write_try_lock() { - return mutex.try_lock() ? OK : ERR_BUSY; + // Attempt to lock the RWLock for writing. True on success, false means it can't lock. + bool write_try_lock() { + return mutex.try_lock(); } }; diff --git a/doc/classes/Mutex.xml b/doc/classes/Mutex.xml index 74f29bdc487..78694ce813d 100644 --- a/doc/classes/Mutex.xml +++ b/doc/classes/Mutex.xml @@ -18,9 +18,9 @@ - + - Tries locking this [Mutex], but does not block. Returns [constant OK] on success, [constant ERR_BUSY] otherwise. + Tries locking this [Mutex], but does not block. Returns [code]true[/code] on success, [code]false[/code] otherwise. [b]Note:[/b] This function returns [constant OK] if the thread already has ownership of the mutex. diff --git a/doc/classes/Semaphore.xml b/doc/classes/Semaphore.xml index 6b2007363ed..d1d126c5cbb 100644 --- a/doc/classes/Semaphore.xml +++ b/doc/classes/Semaphore.xml @@ -17,9 +17,9 @@ - + - Like [method wait], but won't block, so if the value is zero, fails immediately and returns [constant ERR_BUSY]. If non-zero, it returns [constant OK] to report success. + Like [method wait], but won't block, so if the value is zero, fails immediately and returns [code]false[/code]. If non-zero, it returns [code]true[/code] to report success. diff --git a/drivers/coreaudio/audio_driver_coreaudio.cpp b/drivers/coreaudio/audio_driver_coreaudio.cpp index 966a09c6c26..3b2dd95f97d 100644 --- a/drivers/coreaudio/audio_driver_coreaudio.cpp +++ b/drivers/coreaudio/audio_driver_coreaudio.cpp @@ -283,7 +283,7 @@ void AudioDriverCoreAudio::unlock() { } bool AudioDriverCoreAudio::try_lock() { - return mutex.try_lock() == OK; + return mutex.try_lock(); } void AudioDriverCoreAudio::finish() { diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp index 27cb84fb9db..9dad0c93578 100644 --- a/platform/android/audio_driver_opensl.cpp +++ b/platform/android/audio_driver_opensl.cpp @@ -44,7 +44,7 @@ void AudioDriverOpenSL::_buffer_callback( if (pause) { mix = false; } else { - mix = mutex.try_lock() == OK; + mix = mutex.try_lock(); } if (mix) {