Commit 7f79cc2b authored by Michael Arntzenius's avatar Michael Arntzenius

make mutexes check their return codes

parent 2588a25f
......@@ -52,11 +52,20 @@ public:
class PthreadFastMutex {
private:
// NB. I tried using error-checking mutexes (PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP) here in debug-mode but got
// some funky errors. I think we might be deliberately locking/unlocking mutexes on different threads in some
// circumstances. - rntz
pthread_mutex_t mutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
public:
void lock() { pthread_mutex_lock(&mutex); }
void unlock() { pthread_mutex_unlock(&mutex); }
void lock() {
int err = pthread_mutex_lock(&mutex);
ASSERT(!err, "pthread_mutex_lock failed, error code %d", err);
}
void unlock() {
int err = pthread_mutex_unlock(&mutex);
ASSERT(!err, "pthread_mutex_unlock failed, error code %d", err);
}
PthreadFastMutex* asRead() { return this; }
PthreadFastMutex* asWrite() { return this; }
......@@ -64,11 +73,18 @@ public:
class PthreadMutex {
private:
// Ditto comment in PthreadFastMutex re error-checking mutexes. - rntz
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
public:
void lock() { pthread_mutex_lock(&mutex); }
void unlock() { pthread_mutex_unlock(&mutex); }
void lock() {
int err = pthread_mutex_lock(&mutex);
ASSERT(!err, "pthread_mutex_lock failed, error code %d", err);
}
void unlock() {
int err = pthread_mutex_unlock(&mutex);
ASSERT(!err, "pthread_mutex_unlock failed, error code %d", err);
}
PthreadMutex* asRead() { return this; }
PthreadMutex* asWrite() { return this; }
......
......@@ -134,6 +134,7 @@ public:
success = (status == 0) ? 1 : 0;
RELEASE_ASSERT(status == 0 || !waitflag, "could not lock mutex! error %d", status);
return boxBool(status == 0);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment