r288: This commit was manufactured by cvs2svn to create tag 'hv_1_2_0'.
[cinelerra_cv/mob.git] / hvirtual / guicast / mutex.C
blob181fc21398cb75a807d6c507e8d5a71494f4c315
1 #include "bcsignals.h"
2 #include "mutex.h"
4 Mutex::Mutex(char *title)
6         this->title = title;
7         pthread_mutexattr_t attr;
8         pthread_mutexattr_init(&attr);
9 //      pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
10         pthread_mutex_init(&mutex, &attr);
13 Mutex::~Mutex()
15         pthread_mutex_destroy(&mutex);
16         UNSET_ALL_LOCKS(this);
18         
19 int Mutex::lock(char *location)
21         SET_LOCK(this, title, location);
22         if(pthread_mutex_lock(&mutex)) perror("Mutex::lock");
23         return 0;
26 int Mutex::unlock()
28         UNSET_LOCK(this);
29         if(pthread_mutex_unlock(&mutex)) perror("Mutex::unlock");
30         return 0;
33 int Mutex::trylock()
35         return pthread_mutex_trylock(&mutex);
38 int Mutex::reset()
40         pthread_mutex_destroy(&mutex);
41         pthread_mutexattr_t attr;
42         pthread_mutexattr_init(&attr);
43         pthread_mutex_init(&mutex, &attr);
44         return 0;