diff options
| author | Jeff Brown <jeffbrown@google.com> | 2010-10-10 12:52:40 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2010-10-10 12:52:40 -0700 |
| commit | d5da367024c36b317b101fc066a7a4cf992c7d58 (patch) | |
| tree | 87cf98a6514557be5427c462349a0ee9deb9a9dd /include | |
| parent | bcf74accafcdac6c7a940ce28982fc0ef08e111b (diff) | |
| parent | 22cb4ef8ce9c4d5536ac5cee5c40b82bfa56ccc5 (diff) | |
| download | frameworks_base-d5da367024c36b317b101fc066a7a4cf992c7d58.zip frameworks_base-d5da367024c36b317b101fc066a7a4cf992c7d58.tar.gz frameworks_base-d5da367024c36b317b101fc066a7a4cf992c7d58.tar.bz2 | |
am 22cb4ef8: am d577cfd7: Merge "Switch Looper back to using poll() instead of epoll()." into gingerbread
Merge commit '22cb4ef8ce9c4d5536ac5cee5c40b82bfa56ccc5'
* commit '22cb4ef8ce9c4d5536ac5cee5c40b82bfa56ccc5':
Switch Looper back to using poll() instead of epoll().
Diffstat (limited to 'include')
| -rw-r--r-- | include/utils/Looper.h | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/include/utils/Looper.h b/include/utils/Looper.h index 3f00b78..cc51490 100644 --- a/include/utils/Looper.h +++ b/include/utils/Looper.h @@ -20,9 +20,22 @@ #include <utils/threads.h> #include <utils/RefBase.h> #include <utils/KeyedVector.h> +#include <utils/Timers.h> #include <android/looper.h> +// Currently using poll() instead of epoll_wait() since it does a better job of meeting a +// timeout deadline. epoll_wait() typically causes additional delays of up to 10ms +// beyond the requested timeout. +//#define LOOPER_USES_EPOLL +//#define LOOPER_STATISTICS + +#ifdef LOOPER_USES_EPOLL +#include <sys/epoll.h> +#else +#include <sys/poll.h> +#endif + /* * Declare a concrete type for the NDK's looper forward declaration. */ @@ -190,13 +203,54 @@ private: const bool mAllowNonCallbacks; // immutable - int mEpollFd; // immutable int mWakeReadPipeFd; // immutable int mWakeWritePipeFd; // immutable + Mutex mLock; + +#ifdef LOOPER_USES_EPOLL + int mEpollFd; // immutable // Locked list of file descriptor monitoring requests. - Mutex mLock; - KeyedVector<int, Request> mRequests; + KeyedVector<int, Request> mRequests; // guarded by mLock +#else + // The lock guards state used to track whether there is a poll() in progress and whether + // there are any other threads waiting in wakeAndLock(). The condition variables + // are used to transfer control among these threads such that all waiters are + // serviced before a new poll can begin. + // The wakeAndLock() method increments mWaiters, wakes the poll, blocks on mAwake + // until mPolling becomes false, then decrements mWaiters again. + // The poll() method blocks on mResume until mWaiters becomes 0, then sets + // mPolling to true, blocks until the poll completes, then resets mPolling to false + // and signals mResume if there are waiters. + bool mPolling; // guarded by mLock + uint32_t mWaiters; // guarded by mLock + Condition mAwake; // guarded by mLock + Condition mResume; // guarded by mLock + + Vector<struct pollfd> mRequestedFds; // must hold mLock and mPolling must be false to modify + Vector<Request> mRequests; // must hold mLock and mPolling must be false to modify + + ssize_t getRequestIndexLocked(int fd); + void wakeAndLock(); +#endif + +#ifdef LOOPER_STATISTICS + static const int SAMPLED_WAKE_CYCLES_TO_AGGREGATE = 100; + static const int SAMPLED_POLLS_TO_AGGREGATE = 1000; + + nsecs_t mPendingWakeTime; + int mPendingWakeCount; + + int mSampledWakeCycles; + int mSampledWakeCountSum; + nsecs_t mSampledWakeLatencySum; + + int mSampledPolls; + int mSampledZeroPollCount; + int mSampledZeroPollLatencySum; + int mSampledTimeoutPollCount; + int mSampledTimeoutPollLatencySum; +#endif // This state is only used privately by pollOnce and does not require a lock since // it runs on a single thread. @@ -204,6 +258,8 @@ private: size_t mResponseIndex; int pollInner(int timeoutMillis); + void awoken(); + void pushResponse(int events, const Request& request); static void initTLSKey(); static void threadDestructor(void *st); |
