00001 #ifndef __J2K__PThread_Lock_CPP__
00002 #define __J2K__PThread_Lock_CPP__
00003
00004 #include <j2k/Fred/PThread/Lock.hpp>
00005
00006 Lock::Lock(Mutex& arg_mutex, BOOL autoLock)
00007 : mutex(arg_mutex), locked(FALSE)
00008 {
00009 if (autoLock) get();
00010 }
00011
00012
00013 Lock::~Lock() {
00014 release();
00015 }
00016
00017 void Lock::get() {
00018 if (!locked) {
00019 mutex.lock();
00020 locked = TRUE;
00021 }
00022 }
00023
00024 void Lock::release() {
00025 if (locked) {
00026 mutex.unlock();
00027 locked = FALSE;
00028 }
00029 }
00030
00031 void Lock::wait() {
00032 if (!locked) {
00033 cout << "Waiting on an unlocked mutex.\n";
00034 }
00035
00036 mutex.wait();
00037 }
00038
00039 void Lock::notify() {
00040 if (!locked) {
00041 cout << "Notify on an unlocked mutex.\n";
00042 }
00043
00044 mutex.notify();
00045 }
00046
00047 void Lock::notifyAll() {
00048 if (!locked) {
00049 cout << "NotifyAll on an unlocked mutex.\n";
00050 }
00051
00052 mutex.notifyAll();
00053 }
00054
00055 #endif