00001 #ifndef LOCKHOLDER_H 00002 #define LOCKHOLDER_H 00003 00004 #include "ILockable.h" 00005 00006 BOREALIS_NAMESPACE_BEGIN; 00007 00008 // For the entire time this object is instantiated, it holds a lock 00009 // on the specified lock. 00010 class LockHolder 00011 { 00012 public: 00013 LockHolder(ILockable & lockToHold) 00014 throw (exception); 00015 00016 LockHolder(ILockable & lockToHold, bool try_lock) 00017 throw (exception); 00018 00019 virtual ~LockHolder(); 00020 00021 // Convenience methods to let owner of this LockHolder temporarily give up the 00022 // lock. In some cases, this can result in much cleaner code. 00023 void release() 00024 throw (exception); 00025 00026 void reacquire() 00027 throw (exception); 00028 00029 bool is_held(); 00030 private: 00031 ILockable & _lock; 00032 bool _presentlyHeld; 00033 }; 00034 00035 BOREALIS_NAMESPACE_END; 00036 00037 #endif