Mutex::Mutex(const char *title, int recursive)
{
this->title = title;
- this->trace = 0;
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutex_init(&mutex, &attr);
SET_LOCK(this, title, location);
if(pthread_mutex_lock(&mutex)) perror("Mutex::lock");
-
+ set_owner();
// Update recursive status for the first lock
{
if( count <= 0 ) {
printf("Mutex::unlock not locked: %s\n", title);
+ booby();
return 0;
}
// Remove from recursive status
UNSET_LOCK(this);
+ unset_owner();
int ret = pthread_mutex_unlock(&mutex);
if( ret ) fprintf(stderr, "Mutex::unlock: %s\n",strerror(ret));
if( count ) return EBUSY;
int ret = pthread_mutex_trylock(&mutex);
if( ret ) return ret;
+ set_owner();
// Update recursive status for the first lock
if(recursive) {
pthread_mutexattr_init(&attr);
pthread_mutex_init(&mutex, &attr);
UNSET_ALL_LOCKS(this)
+ unset_owner();
trace = 0;
count = 0;
thread_id = 0;