From b406264407a2b83f25c103bacf2a30e9f3cf5a13 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 13 Sep 2023 04:33:08 -0400 Subject: [PATCH] Use assert() instead of throwing Exception in SharedMutex. --- include/mutex.hpp | 16 ++++++++-------- 1 file 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() {