00001 00010 #ifndef OSCL_DOUBLE_LIST_H_INCLUDED 00011 #define OSCL_DOUBLE_LIST_H_INCLUDED 00012 00013 #ifndef OSCLCONFIG_PROC_H_INCLUDED 00014 #include "osclconfig_proc.h" 00015 #endif 00016 00017 00018 #ifndef OSCL_BASE_H_INCLUDED 00019 #include "oscl_base.h" 00020 #endif 00021 00022 #ifndef OSCL_ASSERT_H_INCLUDED 00023 #include "oscl_assert.h" 00024 #endif 00025 00026 00027 //OsclDoubleList and OsclPriorityList are used in the internal scheduler implementation. 00028 //All the IMPORT_C was removed so they're not available as 00029 //public APIs. 00030 00031 template <class T, class S> 00032 inline T* OsclPtrAdd(T* aPtr, S aVal) 00033 { 00034 return((T*)(((uint8*)aPtr) + aVal)); 00035 } 00036 00037 template <class T, class S> 00038 inline T* OsclPtrSub(T* aPtr, S aVal) 00039 { 00040 return((T*)(((uint8*)aPtr) - aVal)); 00041 } 00042 00043 class OsclDoubleLink 00044 { 00045 public: 00046 OsclDoubleLink() : iNext(NULL) {} 00047 void Remove(); 00048 void InsertAfter(OsclDoubleLink* aLink); 00049 void InsertBefore(OsclDoubleLink* aLink); 00050 public: 00051 OsclDoubleLink* iNext; 00052 OsclDoubleLink* iPrev; 00053 }; 00054 00055 00056 class OsclReadyQ; 00057 class OsclPriorityLink : public OsclDoubleLink 00058 { 00059 public: 00060 int32 iPriority; 00061 }; 00062 00063 class OsclDoubleListBase 00064 { 00065 public: 00066 bool IsEmpty() const; 00067 void SetOffset(int32 anOffset); 00068 void Reset(); 00069 OsclDoubleLink* getHead() 00070 { 00071 return &iHead; 00072 } 00073 int32 getOffset() 00074 { 00075 return iOffset; 00076 } 00077 protected: 00078 OsclDoubleListBase(); 00079 OsclDoubleListBase(int32 anOffset); 00080 void InsertHead(OsclAny* aPtr); 00081 void InsertTail(OsclAny* aPtr); 00082 void Insert(OsclAny* aPtr); 00083 protected: 00084 OsclDoubleLink iHead; 00085 int32 iOffset; 00086 private: 00087 OsclDoubleListBase(const OsclDoubleListBase& aList); 00088 OsclDoubleListBase& operator=(const OsclDoubleListBase& aList); 00089 }; 00090 00091 00092 00093 template <class T> 00094 class OsclDoubleList : public OsclDoubleListBase 00095 { 00096 public: 00097 OSCL_INLINE OsclDoubleList(); 00098 OSCL_INLINE OsclDoubleList(int32 anOffset); 00099 OSCL_INLINE void InsertHead(T& aRef); 00100 OSCL_INLINE void InsertTail(T& aRef); 00101 OSCL_INLINE bool IsHead(const T* aPtr) const; 00102 OSCL_INLINE bool IsTail(const T* aPtr) const; 00103 OSCL_INLINE T* Head() const; 00104 OSCL_INLINE T* Tail() const; 00105 }; 00106 00107 template <class T> 00108 class OsclPriorityList : public OsclDoubleListBase 00109 { 00110 public: 00111 OSCL_INLINE OsclPriorityList(); 00112 OSCL_INLINE OsclPriorityList(int32 anOffset); 00113 OSCL_INLINE void Insert(T& aRef); 00114 OSCL_INLINE bool IsHead(const T* aPtr) const; 00115 OSCL_INLINE bool IsTail(const T* aPtr) const; 00116 OSCL_INLINE T* Head() const; 00117 OSCL_INLINE T* Tail() const; 00118 }; 00119 00120 // 00121 class OsclDoubleListBase; 00122 00123 template <class T> 00124 class OsclDoubleRunner 00125 { 00126 public: 00127 OsclDoubleRunner(OsclDoubleListBase& aQue) 00128 { 00129 //save the queue information. 00130 iOffset = aQue.getOffset(); 00131 iHead = aQue.getHead(); 00132 iNext = NULL; 00133 } 00134 00135 void Set(T& aLink) 00136 { 00137 iNext = (OsclDoubleLink*)OsclPtrAdd(aLink, iOffset); 00138 } 00139 00140 //This was inline but ADS 1.2 compiler gets a link error from it... 00141 operator T*() 00142 { 00143 if (iNext) 00144 return ((T *)OsclPtrSub(iNext, iOffset)); 00145 return NULL; 00146 } 00147 00148 T* operator++(int) 00149 { 00150 //get current. 00151 OsclAny* p = NULL; 00152 if (iNext) 00153 p = ((OsclAny *)OsclPtrSub(iNext, iOffset)); 00154 00155 //advance. 00156 if (iNext) 00157 iNext = iNext->iNext; 00158 //return current. 00159 return ((T *)p); 00160 } 00161 00162 T* operator--(int); 00163 00164 public: 00165 void SetToHead() 00166 { 00167 iNext = iHead->iNext; 00168 } 00169 void SetToTail() 00170 { 00171 iNext = iHead->iPrev; 00172 } 00173 protected: 00174 int32 iOffset; 00175 OsclDoubleLink* iHead; 00176 OsclDoubleLink* iNext; 00177 }; 00178 00179 00180 00181 00182 //#if !(OSCL_DISABLE_INLINES) 00183 #include "oscl_double_list.inl" 00184 //#endif 00185 00186 00187 00188 //Some handy macros 00189 #define QUE_ITER_BEGIN(_type,_qname)\ 00190 if (!_qname.IsEmpty())\ 00191 {\ 00192 OsclDoubleRunner <_type> iter(_qname);\ 00193 _type *item;\ 00194 for (iter.SetToHead(); ;iter++)\ 00195 {\ 00196 item=iter;\ 00197 00198 #define QUE_ITER_END(_qname)\ 00199 if (_qname.IsTail(item))\ 00200 break;\ 00201 }\ 00202 } 00203 00204 #endif 00205