一、OPENCORE 之 Scheduler
OsclScheduler
OsclExecScheduler
OsclExecSchedulerCommonBase
1. OsclScheduler::Init()
→ int AuthorDriver::authorThread()
→ OsclScheduler::Init("AndroidAuthorDriver");
→ OSCL_TRY(error, mAuthor = PVAuthorEngineFactory::CreateAuthor(this, this, this));
→ OSCL_EXPORT_REF void OsclScheduler::Init(const char *name, Oscl_DefAlloc *alloc, int nreserve)
→ OsclExecScheduler *sched = OsclExecScheduler::NewL(name, alloc, nreserve);
→ sched->InstallScheduler();
→ OsclExecScheduler * OsclExecScheduler::NewL(const char *name, Oscl_DefAlloc *alloc, int nreserve)
→ self = OSCL_PLACEMENT_NEW(ptr, OsclExecScheduler(alloc));
→ self->ConstructL(name, nreserve);
======
AddToScheduler();
PendForExec();
======
2. OsclExecSchedulerCommonBase::iReadyQ
→ status_t AuthorDriver::enqueueCommand(author_command *ac, media_completion_f comp, void *cookie)
→ mCommandQueue.push_front(ac);
→ PendComplete(OSCL_REQUEST_ERR_NONE);
→ OSCL_EXPORT_REF void OsclActiveObject::PendComplete(int32 aStatus)
→ void PVThreadContext::PendComplete(PVActiveBase *pvbase, int32 aReason, TPVThreadContext aCallingContext)
→ void OsclExecSchedulerCommonBase::PendComplete(PVActiveBase *pvbase, int32 aReason, TPVThreadContext aThreadContext)
→ iReadyQ.Add(pvbase, false); /// 将一个AO添加到iReadyQ中,并恢复BlockingLoopL
3. PVActiveBase::Run()
两种情况,但似乎第二种没用到
iBlockingMode=true
→ int AuthorDriver::authorThread()
→ OsclExecScheduler *sched = OsclExecScheduler::Current();
→ sched->StartScheduler(mSyncSem); // AuthorDriver的构造函数在创建完AuthorThread之后进入阻塞状态,
→ OSCL_EXPORT_REF void OsclExecSchedulerCommonBase::StartScheduler(OsclSemaphore *aSignal)
→ BeginScheduling(true, false);//blocking, non-native
if (aSignal)
aSignal->Signal(); // 在beginScheduling执行完毕之后,AuthorDriver的构造函数就可以退出了
→ OSCL_TRY(err, BlockingLoopL();); // 这里不会立即返回,要等整个程序停止
→ void OsclExecSchedulerCommonBase::BlockingLoopL() //
→ PVActiveBase* pvtimer = UpdateTimers(waitTicks);
→ PVActiveBase* pvactive = iReadyQ.PopTop();
→ CallRunExec(pvactive); // OsclActiveObject
OR
→ iReadyQ.Wait(OsclTickCount::TicksToMsec(waitTicks))
→ iExecTimerQ.Pop(pvtimer);
→ CallRunExec(pvtimer); // OsclTimerObject
OR
→ iReadyQ.Wait(); // Nothing is Ready, 在执行iReadyQ.Add时会调用iSem.Signal()
→ iReadyQ.Signal();
→ void OsclExecSchedulerCommonBase::CallRunExec(PVActiveBase *pvactive)
→ OSCL_TRY_NO_TLS(iErrorTrapImp, err, pvactive->Run(););
iBlockingMode=false
→ OSCL_EXPORT_REF void OsclExecScheduler::RunSchedulerNonBlocking(int32 aCount, int32 &aReady, uint32 &aShortestDelay)
→ BeginScheduling(false, false);//nonblocking, non-native
代码太多,没时写很多东西,简单的贴点代码吧