Browse Source

Use assert() instead of throwing Exception in SharedMutex.

tags/v2.5.0
Andrew Belt 1 year ago
parent
commit
b406264407
1 changed files with 8 additions and 8 deletions
  1. +8
    -8
      include/mutex.hpp

+ 8
- 8
include/mutex.hpp View File

@@ -17,29 +17,29 @@ struct SharedMutex {
pthread_rwlock_t rwlock; pthread_rwlock_t rwlock;


SharedMutex() { SharedMutex() {
if (pthread_rwlock_init(&rwlock, NULL))
throw Exception("pthread_rwlock_init failed");
int err = pthread_rwlock_init(&rwlock, NULL);
assert(!err);
} }
~SharedMutex() { ~SharedMutex() {
pthread_rwlock_destroy(&rwlock); pthread_rwlock_destroy(&rwlock);
} }


void lock() { 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. */ /** Returns whether the lock was acquired. */
bool try_lock() { bool try_lock() {
return pthread_rwlock_trywrlock(&rwlock) == 0; return pthread_rwlock_trywrlock(&rwlock) == 0;
} }
void unlock() { void unlock() {
if (pthread_rwlock_unlock(&rwlock))
throw Exception("pthread_rwlock_unlock failed");
int err = pthread_rwlock_unlock(&rwlock);
assert(!err);
} }


void lock_shared() { 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. */ /** Returns whether the lock was acquired. */
bool try_lock_shared() { bool try_lock_shared() {


Loading…
Cancel
Save