aboutsummaryrefslogtreecommitdiff
path: root/src/threading.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-02-13 16:21:41 +0000
committergingerBill <bill@gingerbill.org>2024-02-13 16:21:41 +0000
commitcbfb32c34c09fd13098f0127bc98c88b53587a97 (patch)
treeb231ef57d4d5a8c5d1f766771287f7cfac0d2784 /src/threading.cpp
parent5cd57a3a7f96e4966a7a17f99363893911fbad0d (diff)
Fix race condition with regards to #soa arrays by using the fields mutex
Diffstat (limited to 'src/threading.cpp')
-rw-r--r--src/threading.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/threading.cpp b/src/threading.cpp
index c283da425..b8bc9b118 100644
--- a/src/threading.cpp
+++ b/src/threading.cpp
@@ -119,17 +119,25 @@ struct MutexGuard {
explicit MutexGuard(RecursiveMutex *rm) noexcept : rm{rm} {
mutex_lock(this->rm);
}
+ explicit MutexGuard(RwMutex *rm) noexcept : rwm{rwm} {
+ rw_mutex_lock(this->rwm);
+ }
explicit MutexGuard(BlockingMutex &bm) noexcept : bm{&bm} {
mutex_lock(this->bm);
}
explicit MutexGuard(RecursiveMutex &rm) noexcept : rm{&rm} {
mutex_lock(this->rm);
}
+ explicit MutexGuard(RwMutex &rwm) noexcept : rwm{&rwm} {
+ rw_mutex_lock(this->rwm);
+ }
~MutexGuard() noexcept {
if (this->bm) {
mutex_unlock(this->bm);
} else if (this->rm) {
mutex_unlock(this->rm);
+ } else if (this->rwm) {
+ rw_mutex_unlock(this->rwm);
}
}
@@ -137,10 +145,12 @@ struct MutexGuard {
BlockingMutex *bm;
RecursiveMutex *rm;
+ RwMutex *rwm;
};
#define MUTEX_GUARD_BLOCK(m) if (MutexGuard GB_DEFER_3(_mutex_guard_){m})
#define MUTEX_GUARD(m) mutex_lock(m); defer (mutex_unlock(m))
+#define RW_MUTEX_GUARD(m) rw_mutex_lock(m); defer (rw_mutex_unlock(m))
struct RecursiveMutex {