00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Benjamin Hadorn (bhadorn@swissinfo.org) * 00003 *************************************************************************** 00004 * Projekt : Zeus 00005 * Module : ThreadMessageQueue 00006 * Package : System 00007 * Author : Benjamin Hadorn 00008 * Datum : $Date: 5.10.09 22:36 $ 00009 * Ablage : $File$ 00010 * System : Cell Computing Model 00011 *************************************************************************** 00012 * Licence: * 00013 * This library is free software; you can redistribute it and/or modify * 00014 * it under the terms of the GNU Lesser General Public License as * 00015 * published by the Free Software Foundation; either version * 00016 * 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00021 * GNU Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00026 ***************************************************************************/ 00027 00028 /*************************************************************************** 00029 Changes : 00030 $Log: /Development_F/StuderWIN/dev/Zeus/src/zeusbase/System/ThreadMessageQueue.h $ 00031 ** 00032 ** 7 5.10.09 22:36 Bha 00033 ** improving speed using inline methods 00034 ** 00035 ** 6 3.09.07 17:21 Mabbuehl 00036 ** VS6 warnings removed. 00037 ** 00038 ** 5 26.02.07 9:00 bha 00039 ** 00040 ** 1 2.10.06 9:21 bha 00041 ** Thread management on Linux and Win32 00042 ***************************************************************************/ 00043 00044 #ifndef ThreadMessageQueueH 00045 #define ThreadMessageQueueH 00046 00047 #include <zeusbase/System/Interfaces/IThreadMessageQueue.hpp> 00048 #include <zeusbase/System/ZObject.h> 00049 #include <zeusbase/System/Queue.hpp> 00050 #include <zeusbase/System/Event.h> 00051 00052 BEGIN_NAMESPACE_Zeus 00053 00054 class TCriticalSection; 00055 00056 /**************************************************************************/ 00060 /**************************************************************************/ 00061 zeusbase_class TThreadMessageQueue : public TZObject, public IThreadMessageQueue 00062 { 00063 public: 00064 TThreadMessageQueue(); 00065 00066 //Methods of IThreadMessageQueue 00067 virtual void MQUALIFIER flush(); 00068 virtual Retval MQUALIFIER processObject(); 00069 virtual Retval MQUALIFIER postObject(ISynchronizeObject& rObject, bool bWaitForCompletion); 00070 virtual void MQUALIFIER lock(); 00071 virtual void MQUALIFIER unlock(); 00072 virtual bool MQUALIFIER isLocked() const; 00073 virtual bool MQUALIFIER isEmpty() const; 00074 00075 //Methods of IZUnknown 00076 MEMORY_MANAGER_DECL 00077 00078 protected: 00079 virtual ~TThreadMessageQueue(); 00080 00081 /**********************************************************************/ 00084 /**********************************************************************/ 00085 inline virtual void onItemPosted(ISynchronizeObject& /* rObject */, bool /* bWaitForCompletion */) 00086 {} 00087 00088 00089 private: 00090 00091 /************************************************************************/ 00094 /************************************************************************/ 00095 class TItemContainer : public TZObject 00096 { 00097 public: 00098 /********************************************************************/ 00101 /********************************************************************/ 00102 inline TItemContainer(ISynchronizeObject& rObject, bool bWaitForCompletion) 00103 : TZObject(), 00104 m_rObject(rObject) 00105 { 00106 m_rObject.addRef(); 00107 m_bWaitForCompletion = bWaitForCompletion; 00108 } 00109 00110 /********************************************************************/ 00113 /********************************************************************/ 00114 inline virtual ~TItemContainer() 00115 { 00116 m_rObject.release(); 00117 } 00118 00119 /********************************************************************/ 00122 /********************************************************************/ 00123 inline ISynchronizeObject& getObject() 00124 { 00125 return m_rObject; 00126 } 00127 00128 /********************************************************************/ 00131 /********************************************************************/ 00132 inline const ISynchronizeObject& getObject() const 00133 { 00134 return m_rObject; 00135 } 00136 00137 /********************************************************************/ 00140 /********************************************************************/ 00141 inline bool isWaitForCompletionSet() 00142 { 00143 return m_bWaitForCompletion; 00144 } 00145 00146 private: 00148 ISynchronizeObject& m_rObject; 00150 bool m_bWaitForCompletion; 00151 00152 }; 00153 00155 TQueue<TItemContainer*> m_lstQueue; 00157 bool m_bLocked; 00159 TCriticalSection& m_rLock; 00160 00161 00162 }; 00163 00164 00165 /**************************************************************************/ 00168 /**************************************************************************/ 00169 inline bool MQUALIFIER TThreadMessageQueue::isLocked() const 00170 { 00171 return m_bLocked; 00172 } 00173 00174 END_NAMESPACE_Zeus 00175 00176 00177 #endif