分类: 嵌入式
2012-06-30 19:56:05
发个以前阅读ce 6.0 powermanager default mode 代码的简单分析:
因为最近玩了下win7的手机,感觉的确快,在同样的硬件设备上,比android 快不是一点点
所以还是看好的win的, 假以时日,一定会卷土重来的!
记得以前CE5.0 下call set power state ,是直接改变电源状态,如果各线程同时调用,会发生状态变化的不完整,所以以前一直通过notify
去改变电源状态,6.0 不同了,估计发现这个问题了,这方面做了改进
另外pdd 层都改成c++的, 代码更清晰了
具体简要分析记录如下:
* classes
PowerStateManager(PMSystemAPI)
PowerState
other system state derive PowerState
* start sync (关键点在于 m_hNotEmpty 就是SystemPowerStateAPI => GetEventHandle(PM_SYSTEM_API_EVENT))
(PmSetSystemPowerState call 不到 实际EnterState !!!)
ThreadRun | PmSetSystemPowerState (pm self first
| call or api call !!!)
GetFirstPowerState (ret CurPowerState) | PlatformSendSystemPowerState
*0 GetAPISignalHandle (wait m_hNotEmpty) | SendSystemPowerState (carry
| out the power state change)
**1 RequestComplete(setEvent m_hComplete | wait m_hEmpty { ( mutex )
pCurPowerState->EnterState(); !!! | ResetEvent(m_hComplete);
| StringCchCopy(m_szStateName,
| MAX_PATH,pwsState);!!!实际
above do enterstate) | *1 SetEvent(m_hNotEmpty);
while (!fDone && pCurPowerState) | **0 wait m_hComplete
(m_hNotEmpty 就是 SystemPowerStateAPI) | setEvent (m_hEmpty) }
case SystemPowerStateAPI |
apiState= RequestedSystemPowerState |
*0 wait m_hNotEmpty |
PowerState * pNewPowerState = GetStateObject(apiState);
pCurPowerState = SetSystemState(pCurPowerState ) ; (=>EnterState!!!)
if (activityEvent == SystemPowerStateAPI) {
RequestComplete();
}
上面看出,ce6 上外部call 并不是直接call api 而是走powermanager thread run 流程
竖线两边表示两个并行运行的部分
* timeout state change: (除了api call event ,所有时间都减wait time)
on --(userilde timeout)--->useridle
--(backlight timeout)-->backlightoff
--(suspend timeout)---->suspend
useridle--(suspend timeout)--->unattend (UserActivity event)-->on
backlightoff-->(suspend timeout)-------->unattend (UserActivity event)-->on
backlightoff-->(UserActivityTimeout)---->useridle
unattend---->(SuspendTimeout)----->suspend 并且 enter unattend count !=0 说明有unattend 请求
unattend 当有enter unattend 请求时 PowerManager ThreadRun 最后状态实作时(SetSystemState) 会去call unattend state的
GetLastNewState 其中判断如果有enter unattend count 请求 next state 仍旧是unattend,否则为suspend
Resuming---->(all timeout)-------------->unattend
suspend (not timeout) to resuming (at extern wakeup)!!!
比如:
1.
userilde timeout = 3
backlightoff timeout =6
suspend timeout =9
on 不动过3秒 ===>useridle 不动过9秒 ===>unattend===>不动0秒===>suspend
如果请求进入unattend 那么 suspend timeout 重新设置,然后leave unattend 后过9秒入 suspend
2.
userilde timeout = 6
backlightoff timeout =3
suspend timeout =9
on 不动过3秒 ===>backlightoff 不动过3秒 ===>useridle 不动过3秒===>unattend===>不动0秒===>suspend (错)
根据ThreadRun==>SetSystemState =>EnterState ==> ReAdjustTimeOuts 不为infinit 并且getNewstate != cur state,的都重新获得timout时间
on 不动过3秒 ===>backlightoff 不动过6秒 ===>useridle 不动过9秒===>unattend===>不动0秒===>suspend (对)
这种情况如果把backlightoff 设置 为半暗, useridle 为全暗 ,这样感觉比较好
(转载请注名出处)