00001 #ifndef __ML_ATOMIC_GUARD_H 00002 #define __ML_ATOMIC_GUARD_H 00003 00004 class MLAtomicGuard 00005 { 00006 public: 00007 MLAtomicGuard(bool val) 00008 :_lock(QReadWriteLock::Recursive),_guard(val) {} 00009 00010 ~MLAtomicGuard() {} 00011 00012 MLAtomicGuard& operator=(bool v) 00013 { 00014 QWriteLocker locker(&_lock); 00015 _guard = v; 00016 return *this; 00017 } 00018 00019 bool operator==(bool v) const 00020 { 00021 QReadLocker locker(&_lock); 00022 return (_guard == v); 00023 } 00024 00025 bool operator!=(bool v) const 00026 { 00027 QReadLocker locker(&_lock); 00028 return (_guard != v); 00029 } 00030 00031 private: 00032 bool _guard; 00033 mutable QReadWriteLock _lock; 00034 }; 00035 00036 #endif