summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Belt <andrewpbelt@gmail.com>2023-09-13 04:33:08 -0400
committerAndrew Belt <andrewpbelt@gmail.com>2023-09-13 04:33:08 -0400
commitb406264407a2b83f25c103bacf2a30e9f3cf5a13 (patch)
treef0e5ec5ce994c25aa04630ead617d111b677268e
parentfb531c5a665fb849c5a1851a7e3de9a8b9ab0069 (diff)
Use assert() instead of throwing Exception in SharedMutex.
-rw-r--r--include/mutex.hpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/include/mutex.hpp b/include/mutex.hpp
index 3d37a761..d924c9f9 100644
--- a/include/mutex.hpp
+++ b/include/mutex.hpp
@@ -17,29 +17,29 @@ struct SharedMutex {
pthread_rwlock_t rwlock;
SharedMutex() {
- if (pthread_rwlock_init(&rwlock, NULL))
- throw Exception("pthread_rwlock_init failed");
+ int err = pthread_rwlock_init(&rwlock, NULL);
+ assert(!err);
}
~SharedMutex() {
pthread_rwlock_destroy(&rwlock);
}
void lock() {
- if (pthread_rwlock_wrlock(&rwlock))
- throw Exception("pthread_rwlock_wrlock failed");
+ int err = pthread_rwlock_wrlock(&rwlock);
+ assert(!err);
}
/** Returns whether the lock was acquired. */
bool try_lock() {
return pthread_rwlock_trywrlock(&rwlock) == 0;
}
void unlock() {
- if (pthread_rwlock_unlock(&rwlock))
- throw Exception("pthread_rwlock_unlock failed");
+ int err = pthread_rwlock_unlock(&rwlock);
+ assert(!err);
}
void lock_shared() {
- if (pthread_rwlock_rdlock(&rwlock))
- throw Exception("pthread_rwlock_rdlock failed");
+ int err = pthread_rwlock_rdlock(&rwlock);
+ assert(!err);
}
/** Returns whether the lock was acquired. */
bool try_lock_shared() {