cmutex.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <cmutex.hxx>
00023 #include <iostream>
00024
00025 namespace control {
00026
00027 cmutex::cmutex():_mutex(0l),
00028 _init(false)
00029 {
00030 }
00031
00032
00033 cmutex::~cmutex()
00034 {
00035 std::cerr << __PRETTY_FUNCTION__ << std::endl << '{' << std::endl << "." << std::endl;
00036
00037 if( _mutex ){
00038 unlock();
00039 pthread_mutex_destroy(_mutex);
00040 _mutex = 0l;
00041 }
00042
00043 std::cerr << std::endl << '}' << std::endl;
00044 }
00045
00046
00047
00048
00049
00054 bool cmutex::init()
00055 {
00056 _mutex= new pthread_mutex_t;
00057 pthread_mutex_init(_mutex, 0l);
00058 _init = true;
00059 __locked = false;
00060 return true;
00061 }
00062
00063
00067 bool cmutex::lock()
00068 {
00069 if(!_init) return false;
00070 if(__locked) return false;
00071 pthread_mutex_lock(_mutex);
00072 __locked = true;
00073 return true;
00074 }
00075
00076
00080 void cmutex::unlock()
00081 {
00082 if(!_init) return;
00083 if(!__locked) return ;
00084 pthread_mutex_unlock(_mutex);
00085 __locked = false;
00086 }
00087 }
API Documentation Generated by:
1.4.0
About the author |

Site started with trial version of DreamWeaver MX 2004 |
Finalizing with

|
Contact | ©2005, Serge Lussier ( Bretzel )