00001 #ifndef __J2K__PThread_Mutex_CPP__
00002 #define __J2K__PThread_Mutex_CPP__
00003
00004 #include <j2k/Fred/PThread/Mutex.hpp>
00005
00006 Mutex::Mutex() {
00007 pthread_mutexattr_init(&mutexAttr);
00008 pthread_mutex_init(&mutex, &mutexAttr);
00009 pthread_condattr_init(&condAttr);
00010 pthread_cond_init(&cond, &condAttr);
00011 }
00012
00013 Mutex::~Mutex() {
00014 pthread_mutex_destroy(&mutex);
00015 pthread_mutexattr_destroy(&mutexAttr);
00016 pthread_cond_destroy(&cond);
00017 pthread_condattr_destroy(&condAttr);
00018 }
00019
00020 void Mutex::lock() {
00021 pthread_mutex_lock(&mutex);
00022 }
00023
00024 void Mutex::unlock() {
00025 pthread_mutex_unlock(&mutex);
00026 }
00027
00028 void Mutex::wait() {
00029 pthread_cond_wait(&cond, &mutex);
00030 }
00031
00032 void Mutex::notify() {
00033 pthread_cond_signal(&cond);
00034 }
00035
00036 void Mutex::notifyAll() {
00037 pthread_cond_broadcast(&cond);
00038 }
00039
00040 #endif