1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18
19 /*! \addtogroup osclproc OSCL Proc
20 *
21 * @{
22 */
23
24 /** \file oscl_double_list.h
25 \brief Internal use types for scheduler
26 */
27 #ifndef OSCL_DOUBLE_LIST_H_INCLUDED
28 #define OSCL_DOUBLE_LIST_H_INCLUDED
29
30 #ifndef OSCLCONFIG_PROC_H_INCLUDED
31 #include "osclconfig_proc.h"
32 #endif
33
34
35 #ifndef OSCL_BASE_H_INCLUDED
36 #include "oscl_base.h"
37 #endif
38
39 #ifndef OSCL_ASSERT_H_INCLUDED
40 #include "oscl_assert.h"
41 #endif
42
43
44 //OsclDoubleList and OsclPriorityList are used in the internal scheduler implementation.
45 //All the IMPORT_C was removed so they're not available as
46 //public APIs.
47
48 template <class T, class S>
OsclPtrAdd(T * aPtr,S aVal)49 inline T* OsclPtrAdd(T* aPtr, S aVal)
50 {
51 return((T*)(((uint8*)aPtr) + aVal));
52 }
53
54 template <class T, class S>
OsclPtrSub(T * aPtr,S aVal)55 inline T* OsclPtrSub(T* aPtr, S aVal)
56 {
57 return((T*)(((uint8*)aPtr) - aVal));
58 }
59
60 class OsclDoubleLink
61 {
62 public:
OsclDoubleLink()63 OsclDoubleLink() : iNext(NULL) {}
64 void Remove();
65 void InsertAfter(OsclDoubleLink* aLink);
66 void InsertBefore(OsclDoubleLink* aLink);
67 public:
68 OsclDoubleLink* iNext;
69 OsclDoubleLink* iPrev;
70 };
71
72
73 class OsclReadyQ;
74 class OsclPriorityLink : public OsclDoubleLink
75 {
76 public:
77 int32 iPriority;
78 };
79
80 class OsclDoubleListBase
81 {
82 public:
83 bool IsEmpty() const;
84 void SetOffset(int32 anOffset);
85 void Reset();
getHead()86 OsclDoubleLink* getHead()
87 {
88 return &iHead;
89 }
getOffset()90 int32 getOffset()
91 {
92 return iOffset;
93 }
94 protected:
95 OsclDoubleListBase();
96 OsclDoubleListBase(int32 anOffset);
97 void InsertHead(OsclAny* aPtr);
98 void InsertTail(OsclAny* aPtr);
99 void Insert(OsclAny* aPtr);
100 protected:
101 OsclDoubleLink iHead;
102 int32 iOffset;
103 private:
104 OsclDoubleListBase(const OsclDoubleListBase& aList);
105 OsclDoubleListBase& operator=(const OsclDoubleListBase& aList);
106 };
107
108
109
110 template <class T>
111 class OsclDoubleList : public OsclDoubleListBase
112 {
113 public:
114 OSCL_INLINE OsclDoubleList();
115 OSCL_INLINE OsclDoubleList(int32 anOffset);
116 OSCL_INLINE void InsertHead(T& aRef);
117 OSCL_INLINE void InsertTail(T& aRef);
118 OSCL_INLINE bool IsHead(const T* aPtr) const;
119 OSCL_INLINE bool IsTail(const T* aPtr) const;
120 OSCL_INLINE T* Head() const;
121 OSCL_INLINE T* Tail() const;
122 };
123
124 template <class T>
125 class OsclPriorityList : public OsclDoubleListBase
126 {
127 public:
128 OSCL_INLINE OsclPriorityList();
129 OSCL_INLINE OsclPriorityList(int32 anOffset);
130 OSCL_INLINE void Insert(T& aRef);
131 OSCL_INLINE bool IsHead(const T* aPtr) const;
132 OSCL_INLINE bool IsTail(const T* aPtr) const;
133 OSCL_INLINE T* Head() const;
134 OSCL_INLINE T* Tail() const;
135 };
136
137 //
138 class OsclDoubleListBase;
139
140 template <class T>
141 class OsclDoubleRunner
142 {
143 public:
OsclDoubleRunner(OsclDoubleListBase & aQue)144 OsclDoubleRunner(OsclDoubleListBase& aQue)
145 {
146 //save the queue information.
147 iOffset = aQue.getOffset();
148 iHead = aQue.getHead();
149 iNext = NULL;
150 }
151
Set(T & aLink)152 void Set(T& aLink)
153 {
154 iNext = (OsclDoubleLink*)OsclPtrAdd(aLink, iOffset);
155 }
156
157 //This was inline but ADS 1.2 compiler gets a link error from it...
158 operator T*()
159 {
160 if (iNext)
161 return ((T *)OsclPtrSub(iNext, iOffset));
162 return NULL;
163 }
164
165 T* operator++(int)
166 {
167 //get current.
168 OsclAny* p = NULL;
169 if (iNext)
170 p = ((OsclAny *)OsclPtrSub(iNext, iOffset));
171
172 //advance.
173 if (iNext)
174 iNext = iNext->iNext;
175 //return current.
176 return ((T *)p);
177 }
178
179 T* operator--(int);
180
181 public:
SetToHead()182 void SetToHead()
183 {
184 iNext = iHead->iNext;
185 }
SetToTail()186 void SetToTail()
187 {
188 iNext = iHead->iPrev;
189 }
190 protected:
191 int32 iOffset;
192 OsclDoubleLink* iHead;
193 OsclDoubleLink* iNext;
194 };
195
196
197
198
199 //#if !(OSCL_DISABLE_INLINES)
200 #include "oscl_double_list.inl"
201 //#endif
202
203
204
205 //Some handy macros
206 #define QUE_ITER_BEGIN(_type,_qname)\
207 if (!_qname.IsEmpty())\
208 {\
209 OsclDoubleRunner <_type> iter(_qname);\
210 _type *item;\
211 for (iter.SetToHead(); ;iter++)\
212 {\
213 item=iter;\
214
215 #define QUE_ITER_END(_qname)\
216 if (_qname.IsTail(item))\
217 break;\
218 }\
219 }
220
221 #endif
222
223 /*! @} */
224