• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*! \addtogroup osclproc OSCL Proc
19  *
20  * @{
21  */
22 
23 
24 /** \file oscl_scheduler_aobase.h
25     \brief Oscl Scheduler internal active object classes.
26 */
27 
28 /** This file defines the PVActiveBase class, which is a common base for
29   All PV ExecObjs on all platforms.
30  */
31 
32 #ifndef OSCL_SCHEDULER_AOBASE_H_INCLUDED
33 #define OSCL_SCHEDULER_AOBASE_H_INCLUDED
34 
35 #ifndef OSCL_SCHEDULER_TYPES_H_INCLUDED
36 #include "oscl_scheduler_types.h"
37 #endif
38 
39 #ifndef OSCL_NAMESTRING_H_INCLUDED
40 #include "oscl_namestring.h"
41 #endif
42 
43 #ifndef OSCL_SCHEDULER_THREAD_CONTEXT_H_INCLUDED
44 #include "oscl_scheduler_threadcontext.h"
45 #endif
46 
47 #ifndef OSCL_SCHEDULER_READYQ_H_INCLUDED
48 #include "oscl_scheduler_readyq.h"
49 #endif
50 
51 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
52 #include "oscl_string_containers.h"
53 #endif
54 
55 /*
56  * Macro for zeroizing the memory of a newly created object
57  *
58  * @param ptr   pointer to the newly created object
59  *
60  * @param size  size of the memory
61  */
62 
63 #define OSCL_ZEROIZE(ptr, size) oscl_memset(ptr, 0, size)
64 
65 /*
66 ** Max length for scheduler and AO names.
67 */
68 #define PVEXECNAMELEN 30
69 
70 #if (PV_SCHED_ENABLE_AO_STATS)
71 /** PV AO statistics
72 */
73 class PVActiveStats
74 {
75     private:
76         //should be constructed only when AO is added to scheduler.
77         PVActiveStats(OsclExecSchedulerCommonBase* aScheduler, const char* aAOName, PVActiveBase* aActiveBase);
78         ~PVActiveStats();
79 
80         void Combine(PVActiveStats&);
81 
82         //Queue link for scheduler iPVStatQ
83         OsclDoubleLink iPVStatQLink;
84 
85         //this AO's scheduler
86         OsclExecSchedulerCommonBase* iScheduler;
87         //AO name
88         OSCL_HeapString<OsclMemAllocator> iAOName;
89         //pointer to original container object.
90         PVActiveBase* iPVActiveBase;
91 
92         uint32 iNumRun;//how many Run calls
93         uint32 iNumRunError;//how many RunError calls
94         int32 iMaxTicksInRun;//max time in any one Run call
95 
96         uint32 iTotalTicksInRun;
97 
98         bool i64Valid;//use 64-bit stats instead of 32-bit
99         int64 i64TotalTicksInRun;//avg number of clock ticks per Run
100 
101         //for internal computation-- percent of total time in this Run
102         float iPercent;
103 
104         int32 iLeave;//last leave code from a Run call
105         uint32 iNumCancel;//how many DoCancel calls.
106 
107         uint32 iNumInstances;//number of scheduler instances of this AO.
108         int32 iPriority;//scheduler priority
109 
110         friend class PVActiveBase;
111         friend class OsclExecScheduler;
112         friend class OsclExecSchedulerCommonBase;
113         friend class OsclActiveObject;
114         friend class OsclTimerObject;
115         friend class OsclReadyQ;
116 };
117 #endif //(PV_SCHED_ENABLE_AO_STATS)
118 
119 
120 /**
121  * PV Scheduler internal AO base class.  Both OsclActiveObject
122  * and OsclTimerObject derive from this class.  For Symbian, this
123  * just container has the desired additions to the basic CTimer or OsclActiveObj
124  * functionality.
125  * For non-Symbian, this class contains the entire AO implementation.
126  */
127 class PVActiveBase
128 {
129     public:
130         uint32 iAddedNum;
131 
132 //iStatus, AddToScheduler(), RemoveFromScheduler etc are needed in PVSchedulerStopper (which is publically derived from OsclActiveObject and OsclActiveObject is publically derived from PVActiveBase )
133 //protected:
134 
135         PVActiveBase(const char name[], int32 pri);
136 
137         virtual ~PVActiveBase();
138 
139         /*
140         ** Each AO has a name, to aid in statistics reporting and debugging.
141         */
142         OsclNameString<PVEXECNAMELEN> iName;
143 
144         /*
145         ** Each AO knows its thread context, including a pointer to the scheduler
146         ** that it is in.
147         */
148         PVThreadContext iThreadContext;
149 
150 #if (PV_SCHED_ENABLE_AO_STATS)
151         /*
152         ** AO statistics
153         */
154         PVActiveStats *iPVActiveStats;
155         friend class PVActiveStats;
156 #endif
157 
158 
159         /*
160         ** Non-Symbian AO implementation.
161         */
162 
163         /*
164         ** Queue link for scheduler iExecTimerQ or iReadyQ.
165         */
166         TReadyQueLink iPVReadyQLink;
167 
168         /*
169         ** Return true if this AO is in any queue.
170         */
IsInAnyQ()171         bool IsInAnyQ()
172         {
173             return(iPVReadyQLink.iIsIn != NULL);
174         }
175 
176         /*
177         ** The executing flag is set whenever a request is active (pending
178         ** or complete).  The AO is de-activated by scheduler just before
179         ** calling the Run.
180         */
181         bool iBusy;
182 
183         /**
184         The request status associated with an asynchronous request.
185 
186         This is passed as a parameter to all asynchronous service providers.
187 
188         The active scheduler uses this to check whether the active object's request
189         has completed.
190 
191         The function can use the completion code to judge the success or otherwise
192         of the request.
193 
194         Request status contains one of the values
195         OSCL_REQUEST_ERR_NONE: request completed with no error,
196            or request is not active.
197         OSCL_REQUEST_PENDING: request is active & pending
198         OSCL_REQUEST_ERR_CANCEL: request was canceled before completion.
199         or any user-defined value.
200         */
201         OsclAOStatus iStatus;
202 
203         /**
204         * Virtual routine that gets called if the active object's
205         * Run routine leaves.
206         * @param aError: the leave code generated by the Run.
207         * @return :returns OsclErrNone if the error was handled,
208         *   or returns the input aError value if not handled.
209         */
210         virtual int32 RunError(int32 aError) = 0;
211 
212         /**
213         Handles an active object's request completion event.
214 
215         A derived class must provide an implementation to handle the
216         completed request. If appropriate, it may issue another request.
217 
218         The function is called by the active scheduler when a request
219         completion event occurs, i.e. after the active scheduler's
220         WaitForAnyRequest() function completes.
221 
222         Before calling this active object's Run() function, the active scheduler
223         has:
224 
225         1. decided that this is the highest priority active object with
226            a completed request
227 
228         2. marked this active object's request as complete (i.e. the request is no
229            longer outstanding)
230 
231         Run() runs under a trap harness in the active scheduler. If it leaves,
232         then the active scheduler calls ExecError() to handle the leave.
233 
234         Note that once the active scheduler's Start() function has been called,
235         all user code is run under one of the program's active object's Run() or
236         RunError() functions.
237         */
238         virtual void Run() = 0;
239 
240         /**
241         Implements cancellation of an outstanding request.
242 
243         This function is called as part of the active object's Cancel().
244 
245         It must call the appropriate cancel function offered by the active object's
246         asynchronous service provider. The asynchronous service provider's cancel
247         is expected to act immediately.
248 
249         DoCancel() must not wait for event completion; this is handled by Cancel().
250         */
251         virtual void DoCancel() = 0;
252 
253         /*
254         ** Common methods to support OsclActiveObject and OsclTimerObject APIs
255         */
256         void AddToScheduler();
257         void RemoveFromScheduler();
258         void Destroy();
259         void Activate();
260         OSCL_IMPORT_REF bool IsAdded()const;
261         void Cancel();
262 
263         friend class OsclSchedulerCommonBase;
264         friend class OsclActiveObject;
265         friend class OsclTimerObject;
266         friend class OsclReadyQ;
267         friend class OsclReadyCompare;
268         friend class OsclReadySetPosition;
269         friend class OsclExecScheduler;
270 
271 };
272 
273 #endif
274 
275 
276 
277 
278 /*! @} */
279 
280