mirror of
https://github.com/privacore/open-source-search-engine.git
synced 2025-01-22 02:18:42 -05:00
7ff2381952
Use -DDEBUG_MUTEXES to enable heavy-duty error checking on mutexes
38 lines
722 B
C++
38 lines
722 B
C++
#include "GbMutex.h"
|
|
#include <errno.h>
|
|
#include <assert.h>
|
|
|
|
//The initialization and raw copying of pthread_mutex_t(init-value) is not
|
|
//portable, but works fine on linux, solaris, hp-ux, ...
|
|
|
|
#ifndef DEBUG_MUTEXES
|
|
|
|
pthread_mutex_t const GbMutex::mtx_init = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
#else
|
|
|
|
pthread_mutex_t const GbMutex::mtx_init = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
|
|
|
|
GbMutex::~GbMutex() {
|
|
int rc = pthread_mutex_destroy(&mtx);
|
|
assert(rc==0);
|
|
}
|
|
|
|
|
|
void GbMutex::lock() {
|
|
int rc = pthread_mutex_lock(&mtx);
|
|
assert(rc==0);
|
|
}
|
|
|
|
void GbMutex::unlock() {
|
|
int rc = pthread_mutex_unlock(&mtx);
|
|
assert(rc==0);
|
|
}
|
|
|
|
void GbMutex::verify_is_locked() {
|
|
int rc = pthread_mutex_lock(&mtx);
|
|
assert(rc==EDEADLK);
|
|
}
|
|
|
|
#endif
|