00001
00013 #ifndef OSCL_SCHEDULER_H_INCLUDED
00014 #define OSCL_SCHEDULER_H_INCLUDED
00015
00016 #ifndef OSCL_SCHEDULER_TYPES_H_INCLUDED
00017 #include "oscl_scheduler_types.h"
00018 #endif
00019
00020 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED
00021 #include "oscl_scheduler_ao.h"
00022 #endif
00023
00024 #ifndef OSCL_SCHEDULER_THREADCONTEXT_H_INCLUDED
00025 #include "oscl_scheduler_threadcontext.h"
00026 #endif
00027
00028 #ifndef OSCL_MUTEX_H_INCLUDED
00029 #include "oscl_mutex.h"
00030 #endif
00031
00032 #ifndef OSCL_SEMAPHORE_H_INCLUDED
00033 #include "oscl_semaphore.h"
00034 #endif
00035
00036 #ifndef OSCL_SCHEDULER_READYQ_H_INCLUDED
00037 #include "oscl_scheduler_readyq.h"
00038 #endif
00039
00040 #ifndef OSCL_DEFALLOC_H_INCLUDED
00041 #include "oscl_defalloc.h"
00042 #endif
00043
00044 #ifndef OSCL_MEM_H_INCLUDED
00045 #include "oscl_mem.h"
00046 #endif
00047
00048 class Oscl_DefAlloc;
00049 class OsclCoeActiveScheduler;
00050
00051
00055 class OsclScheduler
00056 {
00057 public:
00067 OSCL_IMPORT_REF static void Init(const char *name, Oscl_DefAlloc *alloc = NULL, int nreserve = 20);
00068
00069
00074 OSCL_IMPORT_REF static void Cleanup();
00075 };
00076
00077
00082 #define PVSCHEDNAMELEN 30
00083
00084 class PVSchedulerStopper;
00085 class PVJump;
00086 class PVLogger;
00087
00095 class OsclSchedulerObserver
00096 {
00097 public:
00107 virtual void OsclSchedulerTimerCallback(OsclAny* aContext, uint32 aDelayMsec) = 0;
00108
00118 virtual void OsclSchedulerReadyCallback(OsclAny* aContext) = 0;
00119
00120 virtual ~OsclSchedulerObserver() {}
00121 };
00122
00123
00124
00125
00126
00127
00128 class OsclExecSchedulerCommonBase
00129 {
00130 public:
00140 OSCL_IMPORT_REF void StartScheduler(OsclSemaphore *sem = NULL);
00141
00146 OSCL_IMPORT_REF void StopScheduler();
00147
00152 OSCL_IMPORT_REF void SuspendScheduler();
00153
00158 OSCL_IMPORT_REF void ResumeScheduler();
00159
00165 OSCL_IMPORT_REF void StartNativeScheduler();
00166
00170 OSCL_IMPORT_REF static OsclNameString<PVSCHEDNAMELEN> *GetName();
00171
00175 OSCL_IMPORT_REF static uint32 GetId();
00176
00177
00178 protected:
00179
00180
00181
00182 virtual ~OsclExecSchedulerCommonBase();
00183 void InstallScheduler();
00184 void UninstallScheduler();
00185 friend class OsclScheduler;
00186
00187 protected:
00188 void Error(int32 anError) const;
00189
00190 protected:
00191 static OsclExecSchedulerCommonBase* GetScheduler();
00192 static OsclExecSchedulerCommonBase* SetScheduler(OsclExecSchedulerCommonBase*);
00193 friend class PVThreadContext;
00194 friend class OsclCoeActiveScheduler;
00195
00196 protected:
00197 OsclExecSchedulerCommonBase(Oscl_DefAlloc*);
00198 virtual void ConstructL(const char *name, int);
00199
00200 void BeginScheduling(bool blocking, bool native);
00201 void EndScheduling();
00202
00203 void BlockingLoopL();
00204
00205 bool iBlockingMode;
00206 bool iNativeMode;
00207
00208 bool IsStarted();
00209 inline bool IsInstalled();
00210
00211
00212
00213 PVSchedulerStopper *iStopper;
00214 OsclNoYieldMutex iStopperCrit;
00215
00216
00217 PVThreadContext iThreadContext;
00218
00219
00220 OsclNameString<PVSCHEDNAMELEN> iName;
00221
00222
00223 bool iDoStop;
00224 bool iDoSuspend;
00225 bool iSuspended;
00226 OsclSemaphore iResumeSem;
00227
00228 OsclErrorTrapImp* iErrorTrapImp;
00229
00230
00231 OsclReadyQ iReadyQ;
00232
00233
00234
00235 OsclTimerQ iExecTimerQ;
00236 void AddToExecTimerQ(PVActiveBase *active, uint32);
00237
00238 void PendComplete(PVActiveBase *, int32 aReason, TPVThreadContext aContext);
00239 void RequestCanceled(PVActiveBase*);
00240
00241
00242 PVActiveBase* UpdateTimers(uint32 &aDelay);
00243 PVActiveBase* UpdateTimersMsec(uint32 &aDelay);
00244 PVActiveBase* WaitForReadyAO();
00245 void CallRunExec(PVActiveBase*);
00246
00247 static const uint32 iTimeCompareThreshold;
00248 friend class OsclTimerCompare;
00249 friend class OsclReadyQ;
00250
00251 friend class OsclError;
00252
00253
00254
00255 uint32 iNumAOAdded;
00256
00257
00258 #if (PV_SCHED_ENABLE_AO_STATS)
00259 OsclDoubleList<PVActiveStats> iPVStatQ;
00260 enum TOtherExecStats
00261 {
00262 EOtherExecStats_WaitTime
00263 , EOtherExecStats_QueueTime
00264 , EOtherExecStats_NativeOS
00265 , EOtherExecStats_ReleaseTime
00266 , EOtherExecStats_Last
00267 };
00268 PVActiveStats* iOtherExecStats[EOtherExecStats_Last];
00269 void ConstructStatQ();
00270 void BeginStats();
00271 void EndStats();
00272 static void ShowStats(PVActiveStats *active);
00273 static void ShowSummaryStats(PVActiveStats *active, PVLogger*, int64, int64&, float&);
00274 void CleanupStatQ();
00275 uint8* iTotalTicksTemp;
00276 int64 iGrandTotalTicks;
00277 float iTotalPercent;
00278 friend class PVActiveStats;
00279 uint32 iTime;
00280 int32 iDelta;
00281 PVActiveStats* iPVStats;
00282 #endif //PV_SCHED_ENABLE_AO_STATS
00283
00284
00285 PVActiveBase *FindPVBase(PVActiveBase *active, OsclDoubleList<PVActiveBase> &);
00286 void CleanupExecQ();
00287 void InitExecQ(int);
00288
00289 PVLogger *iLogger;
00290 PVLogger* iDebugLogger;
00291
00292 #if(PV_SCHED_ENABLE_PERF_LOGGING)
00293
00294 char* iLogPerfIndentStr;
00295 int32 iLogPerfIndentStrLen;
00296 uint32 iLogPerfTotal;
00297 void ResetLogPerf();
00298 void IncLogPerf(uint32);
00299 #endif
00300
00301 Oscl_DefAlloc *iAlloc;
00302 OsclMemAllocator iDefAlloc;
00303
00304 friend class OsclActiveObject;
00305 friend class OsclTimerObject;
00306 friend class PVActiveBase;
00307 friend class PVSchedulerStopper;
00308
00309
00310 friend class OsclExecScheduler;
00311 };
00312
00313 class OsclErrorTrapImp;
00314
00315 class OsclExecScheduler: public OsclExecSchedulerCommonBase
00316 , public OsclExecSchedulerBase
00317 {
00318 public:
00323 OSCL_IMPORT_REF static OsclExecScheduler* Current();
00324
00347 OSCL_IMPORT_REF void RunSchedulerNonBlocking(int32 aTargetCount, int32 &aReady, uint32 &aDelayMsec);
00348
00356 OSCL_IMPORT_REF void RegisterForCallback(OsclSchedulerObserver* aCallback, OsclAny* aCallbackContext);
00357
00358
00359 private:
00360 static OsclExecScheduler *NewL(const char *name, Oscl_DefAlloc *a, int nreserve);
00361 ~OsclExecScheduler();
00362 friend class OsclScheduler;
00363
00364
00365 OsclExecScheduler(Oscl_DefAlloc*);
00366 void ConstructL(const char *name, int);
00367
00368 };
00369
00370
00375 class PVSchedulerStopper: public OsclActiveObject
00376 {
00377 public:
00378 PVSchedulerStopper();
00379 ~PVSchedulerStopper();
00380 private:
00381 void Run();
00382 };
00383
00384
00385 #endif
00386
00387