TimedEventQueue::event_id TimedEventQueue::postTimedEvent( const sp<Event> &event, int64_t realtime_us) { Mutex::Autolock autoLock(mLock); event->setEventID(mNextEventID++); List<QueueItem>::iterator it = mQueue.begin(); while (it != mQueue.end() && realtime_us >= (*it).realtime_us) { ++it; } QueueItem item; item.event = event; item.realtime_us = realtime_us; item.has_wakelock = false; if (it == mQueue.begin()) { mQueueHeadChangedCondition.signal(); } if (realtime_us > ALooper::GetNowUs() + kWakelockMinDelay) { acquireWakeLock_l(); item.has_wakelock = true; } mQueue.insert(it, item); mQueueNotEmptyCondition.signal(); return event->eventID(); }
bool SimpleEventQueue::postTimedEvent(const sp<Event>& event, int64_t realtime_us) { Mutex::Autolock _l(mLock); List<QueueItem>::iterator iter = mQueue.begin(); while (iter != mQueue.end() && realtime_us >= iter->realtime_us) { ++iter; } QueueItem item; item.event = event; item.realtime_us = realtime_us;//getRealTimeUs(); item.has_wakelock = false; if (iter == mQueue.begin()) { mQueueHeadChangedCondition.signal(); } if (realtime_us > getRealTimeUs() + kWakelockMinDelay) { acquireWakeLock_l(); item.has_wakelock = true; } mQueue.insert(iter, item); mQueueNotEmptyCondition.signal(); return true; }