r606: convert ODDLEADS to TOP_FIRST and EVENLEADS to BOTTOM_FIRST
[cinelerra_cv/mob.git] / guicast / mutex.C
blob790fd3e9a1428d56ed253c35a10830801308c96a
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         SET_LOCK2
24         return 0;
27 int Mutex::unlock()
29         UNSET_LOCK(this);
30         if(pthread_mutex_unlock(&mutex)) perror("Mutex::unlock");
31         return 0;
34 int Mutex::trylock()
36         return pthread_mutex_trylock(&mutex);
39 int Mutex::reset()
41         pthread_mutex_destroy(&mutex);
42         pthread_mutexattr_t attr;
43         pthread_mutexattr_init(&attr);
44         pthread_mutex_init(&mutex, &attr);
45         UNSET_ALL_LOCKS(this)
46         return 0;