Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

mutex.C

Go to the documentation of this file.
00001 #include "bcsignals.h"
00002 #include "mutex.h"
00003 
00004 Mutex::Mutex(char *title)
00005 {
00006         this->title = title;
00007         pthread_mutexattr_t attr;
00008         pthread_mutexattr_init(&attr);
00009 //      pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
00010         pthread_mutex_init(&mutex, &attr);
00011 }
00012 
00013 Mutex::~Mutex()
00014 {
00015         pthread_mutex_destroy(&mutex);
00016         UNSET_ALL_LOCKS(this);
00017 }
00018         
00019 int Mutex::lock(char *location)
00020 {
00021         SET_LOCK(this, title, location);
00022         if(pthread_mutex_lock(&mutex)) perror("Mutex::lock");
00023         SET_LOCK2
00024         return 0;
00025 }
00026 
00027 int Mutex::unlock()
00028 {
00029         UNSET_LOCK(this);
00030         if(pthread_mutex_unlock(&mutex)) perror("Mutex::unlock");
00031         return 0;
00032 }
00033 
00034 int Mutex::trylock()
00035 {
00036         return pthread_mutex_trylock(&mutex);
00037 }
00038 
00039 int Mutex::reset()
00040 {
00041         pthread_mutex_destroy(&mutex);
00042         pthread_mutexattr_t attr;
00043         pthread_mutexattr_init(&attr);
00044         pthread_mutex_init(&mutex, &attr);
00045         UNSET_ALL_LOCKS(this)
00046         return 0;
00047 }

Generated on Sun Jan 8 13:26:35 2006 for Guicast-svn by  doxygen 1.4.4