00001 #ifndef _LCD_LOCK_H_ 00002 #define _LCD_LOCK_H_ 00003 00004 #include "LCDMutex.h" 00005 00006 #include <unistd.h> 00007 #include <pthread.h> 00008 00015 class LCDLock 00016 { 00017 private: 00018 LCDMutex *_lcdMutex; 00019 ::pthread_mutex_t *_posixMutex; 00020 bool _useLCD; 00021 00022 public: 00028 LCDLock(LCDMutex *mutex) 00029 { 00030 _lcdMutex = mutex; 00031 ::pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0); 00032 _lcdMutex->lock(); 00033 _useLCD = true; 00034 } 00040 LCDLock(::pthread_mutex_t *mutex) 00041 { 00042 _posixMutex = mutex; 00043 ::pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0); 00044 ::pthread_mutex_lock(_posixMutex); 00045 _useLCD = false; 00046 } 00047 00053 ~LCDLock() 00054 { 00055 if (_useLCD) 00056 { 00057 _lcdMutex->unlock(); 00058 } 00059 else 00060 { 00061 ::pthread_mutex_unlock(_posixMutex); 00062 } 00063 ::pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0); 00064 } 00065 }; 00066 00067 #endif