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;

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() {


Loading…
Cancel
Save