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_CONDITIONVARIABLE_H 00014 #define _SUPPORT_CONDITIONVARIABLE_H 00015 00021 #include <support/SupportDefs.h> 00022 #include <support/Atom.h> 00023 00024 #if _SUPPORTS_NAMESPACE 00025 namespace palmos { 00026 namespace support { 00027 #endif 00028 00033 class SLocker; 00034 00035 /*-------------------------------------------------------------*/ 00036 /*----- SConditionVariable class ------------------------------*/ 00037 00039 class SConditionVariable 00040 { 00041 public: 00042 SConditionVariable(); 00043 SConditionVariable(const char* name); 00044 ~SConditionVariable(); 00045 00047 void Wait(); 00048 00050 00053 void Wait(SLocker& locker); 00054 00056 00058 void Open(); 00059 00061 00062 void Close(); 00063 00065 00066 void Broadcast(); 00067 00068 private: 00069 // SConditionVariable can't be copied 00070 SConditionVariable(const SConditionVariable&); 00071 SConditionVariable& operator = (const SConditionVariable&); 00072 00073 volatile int32_t m_var; 00074 }; 00075 00076 /*-------------------------------------------------------------*/ 00077 /*----- SConditionAtom class ----------------------------------*/ 00078 00079 class SConditionAtom : public virtual SAtom 00080 { 00081 public: 00082 inline SConditionAtom(SConditionVariable *cv) :m_cv(cv) { } 00083 inline virtual ~SConditionAtom() { m_cv->Open(); } 00084 00085 inline void Wait() { m_cv->Wait(); } 00086 inline void Wait(SLocker &locker) { m_cv->Wait(locker); } 00087 inline void Open() { m_cv->Open(); } 00088 inline void Close() { m_cv->Close(); } 00089 inline void Broadcast() { m_cv->Broadcast(); } 00090 00091 private: 00092 SConditionAtom(); 00093 SConditionAtom(const SConditionAtom &); 00094 SConditionVariable *m_cv; 00095 }; 00096 00097 /*-------------------------------------------------------------*/ 00098 /*-------------------------------------------------------------*/ 00099 00102 #if _SUPPORTS_NAMESPACE 00103 } } // namespace palmos::support 00104 #endif 00105 00106 #endif /* _SUPPORT_CONDITIONVARIABLE_H */