00001 /* 00002 * Copyright (c) 2005 Palmsource, Inc. 00003 * 00004 * This software is licensed as described in the file LICENSE, which 00005 * you should have received as part of this distribution. The terms 00006 * are also available at http://www.openbinder.org/license.html. 00007 * 00008 * This software consists of voluntary contributions made by many 00009 * individuals. For the exact contribution history, see the revision 00010 * history and logs, available at http://www.openbinder.org 00011 */ 00012 00013 #ifndef _SUPPORT_AUTOLOCK_H 00014 #define _SUPPORT_AUTOLOCK_H 00015 00021 #include <support/Locker.h> 00022 00023 #if _SUPPORTS_NAMESPACE 00024 namespace palmos { 00025 namespace support { 00026 #endif 00027 00028 /*-----------------------------------------------------------------*/ 00029 /*----- SAutolock class -------------------------------------------*/ 00030 00035 00036 00053 class SAutolock 00054 { 00055 public: 00056 inline SAutolock(const lock_status_t& status); 00057 inline SAutolock(); 00058 inline ~SAutolock(); 00059 inline bool IsLocked(); 00060 00061 inline void SetTo(const lock_status_t& status); 00062 inline void Unlock(); 00063 00064 private: 00065 SAutolock(const SAutolock&); 00066 SAutolock& operator = (const SAutolock&); 00067 00068 lock_status_t m_status; 00069 }; 00070 00073 /*-------------------------------------------------------------*/ 00074 /*---- No user serviceable parts after this -------------------*/ 00075 00076 inline SAutolock::SAutolock(const lock_status_t& status) 00077 : m_status(status) 00078 { 00079 } 00080 00081 inline SAutolock::SAutolock() 00082 : m_status(-1) 00083 { 00084 } 00085 00086 inline SAutolock::~SAutolock() 00087 { 00088 m_status.unlock(); 00089 } 00090 00091 inline bool SAutolock::IsLocked() 00092 { 00093 return m_status.is_locked(); 00094 } 00095 00096 inline void SAutolock::SetTo(const lock_status_t& status) 00097 { 00098 m_status.unlock(); 00099 m_status = status; 00100 } 00101 00102 inline void SAutolock::Unlock() 00103 { 00104 m_status.unlock(); 00105 m_status = lock_status_t(-1); 00106 } 00107 00108 #if _SUPPORTS_NAMESPACE 00109 } } // namespace palmos::support 00110 #endif 00111 00112 #endif /* _SUPPORT_AUTOLOCK_H */