summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-27 15:40:43 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-27 15:40:43 +0100
commitf0e3c3f4c398f25ad5d9f9133c0ff6162e6716ad (patch)
tree3e8d948be734a26d884cea35bc3caa8f78eaf71f /core
parent518b9e5801a19229805fe837d7d0cf92920ad413 (diff)
parentf630940591f66cc98fb52f2873e8c9f1eb1ee056 (diff)
Merge pull request #72168 from RandomShaper/sensible_lock_return
Booleanize various sync primitives' wait & locking methods
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp6
-rw-r--r--core/core_bind.h4
-rw-r--r--core/math/bvh.h2
-rw-r--r--core/os/mutex.h5
-rw-r--r--core/os/rw_lock.h14
5 files changed, 14 insertions, 17 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 96e1da9dde..9de901754a 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 c0c87fd009..8852463234 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 357d483375..ea8289607e 100644
--- a/core/math/bvh.h
+++ b/core/math/bvh.h
@@ -780,7 +780,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 c91917a9a1..ceedcb235a 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 <mutex>
@@ -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 e290b7c00b..7b232600b7 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 <shared_mutex>
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();
}
};