Booleanize various sync primitives' wait & locking methods

This commit is contained in:
Pedro J. Estébanez 2023-01-27 11:04:41 +01:00
parent 9f74f0f6c5
commit f630940591
9 changed files with 20 additions and 23 deletions

View File

@ -1105,8 +1105,8 @@ void Semaphore::wait() {
semaphore.wait(); semaphore.wait();
} }
Error Semaphore::try_wait() { bool Semaphore::try_wait() {
return semaphore.try_wait() ? OK : ERR_BUSY; return semaphore.try_wait();
} }
void Semaphore::post() { void Semaphore::post() {
@ -1125,7 +1125,7 @@ void Mutex::lock() {
mutex.lock(); mutex.lock();
} }
Error Mutex::try_lock() { bool Mutex::try_lock() {
return mutex.try_lock(); return mutex.try_lock();
} }

View File

@ -361,7 +361,7 @@ class Mutex : public RefCounted {
public: public:
void lock(); void lock();
Error try_lock(); bool try_lock();
void unlock(); void unlock();
}; };
@ -373,7 +373,7 @@ class Semaphore : public RefCounted {
public: public:
void wait(); void wait();
Error try_wait(); bool try_wait();
void post(); void post();
}; };

View File

@ -784,7 +784,7 @@ private:
if (p_thread_safe) { if (p_thread_safe) {
_mutex = p_mutex; _mutex = p_mutex;
if (_mutex->try_lock() != OK) { if (!_mutex->try_lock()) {
WARN_PRINT("Info : multithread BVH access detected (benign)"); WARN_PRINT("Info : multithread BVH access detected (benign)");
_mutex->lock(); _mutex->lock();
} }

View File

@ -31,7 +31,6 @@
#ifndef MUTEX_H #ifndef MUTEX_H
#define MUTEX_H #define MUTEX_H
#include "core/error/error_list.h"
#include "core/typedefs.h" #include "core/typedefs.h"
#include <mutex> #include <mutex>
@ -49,8 +48,8 @@ public:
mutex.unlock(); mutex.unlock();
} }
_ALWAYS_INLINE_ Error try_lock() const { _ALWAYS_INLINE_ bool try_lock() const {
return mutex.try_lock() ? OK : ERR_BUSY; return mutex.try_lock();
} }
}; };

View File

@ -31,8 +31,6 @@
#ifndef RW_LOCK_H #ifndef RW_LOCK_H
#define RW_LOCK_H #define RW_LOCK_H
#include "core/error/error_list.h"
#include <shared_mutex> #include <shared_mutex>
class RWLock { class RWLock {
@ -49,9 +47,9 @@ public:
mutex.unlock_shared(); mutex.unlock_shared();
} }
// Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock. // Attempt to lock the RWLock for reading. True on success, false means it can't lock.
Error read_try_lock() const { bool read_try_lock() const {
return mutex.try_lock_shared() ? OK : ERR_BUSY; return mutex.try_lock_shared();
} }
// Lock the rwlock, block if locked by someone else // Lock the rwlock, block if locked by someone else
@ -64,9 +62,9 @@ public:
mutex.unlock(); mutex.unlock();
} }
// Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock. // Attempt to lock the RWLock for writing. True on success, false means it can't lock.
Error write_try_lock() { bool write_try_lock() {
return mutex.try_lock() ? OK : ERR_BUSY; return mutex.try_lock();
} }
}; };

View File

@ -18,9 +18,9 @@
</description> </description>
</method> </method>
<method name="try_lock"> <method name="try_lock">
<return type="int" enum="Error" /> <return type="bool" />
<description> <description>
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. [b]Note:[/b] This function returns [constant OK] if the thread already has ownership of the mutex.
</description> </description>
</method> </method>

View File

@ -17,9 +17,9 @@
</description> </description>
</method> </method>
<method name="try_wait"> <method name="try_wait">
<return type="int" enum="Error" /> <return type="bool" />
<description> <description>
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.
</description> </description>
</method> </method>
<method name="wait"> <method name="wait">

View File

@ -283,7 +283,7 @@ void AudioDriverCoreAudio::unlock() {
} }
bool AudioDriverCoreAudio::try_lock() { bool AudioDriverCoreAudio::try_lock() {
return mutex.try_lock() == OK; return mutex.try_lock();
} }
void AudioDriverCoreAudio::finish() { void AudioDriverCoreAudio::finish() {

View File

@ -44,7 +44,7 @@ void AudioDriverOpenSL::_buffer_callback(
if (pause) { if (pause) {
mix = false; mix = false;
} else { } else {
mix = mutex.try_lock() == OK; mix = mutex.try_lock();
} }
if (mix) { if (mix) {