From 45e0acb41acf30a1b7592ea7e695d96aca3ccd3b Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Tue, 7 Sep 2010 15:28:30 -0700 Subject: Modify native ALooper to take an explicit ident. The ALooper API now uses an explicit "identifier" for the integer that is returned rather than implicitly using the fd. This allows the APIs that had the fd to be a little more sane. Change-Id: I8507f535ad484c0bdc4a1bd016d87bb09acd7ff0 --- libs/utils/PollLoop.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'libs/utils/PollLoop.cpp') diff --git a/libs/utils/PollLoop.cpp b/libs/utils/PollLoop.cpp index f740fa0d52..6d3eeee15c 100644 --- a/libs/utils/PollLoop.cpp +++ b/libs/utils/PollLoop.cpp @@ -95,6 +95,7 @@ void PollLoop::openWakePipe() { RequestedCallback requestedCallback; requestedCallback.callback = NULL; requestedCallback.looperCallback = NULL; + requestedCallback.ident = 0; requestedCallback.data = NULL; mRequestedCallbacks.insertAt(requestedCallback, 0); } @@ -116,7 +117,7 @@ int32_t PollLoop::pollOnce(int timeoutMillis, int* outEvents, void** outData) { mPendingFdsPos++; if (outEvents != NULL) *outEvents = pending.events; if (outData != NULL) *outData = pending.data; - return pending.fd; + return pending.ident; } mLock.lock(); @@ -182,6 +183,7 @@ int32_t PollLoop::pollOnce(int timeoutMillis, int* outEvents, void** outData) { const RequestedCallback& requestedCallback = mRequestedCallbacks.itemAt(i); PendingCallback pending; pending.fd = requestedFd.fd; + pending.ident = requestedCallback.ident; pending.events = revents; pending.callback = requestedCallback.callback; pending.looperCallback = requestedCallback.looperCallback; @@ -191,7 +193,7 @@ int32_t PollLoop::pollOnce(int timeoutMillis, int* outEvents, void** outData) { mPendingCallbacks.push(pending); } else if (pending.fd != mWakeReadPipeFd) { if (result == POLL_CALLBACK) { - result = pending.fd; + result = pending.ident; if (outEvents != NULL) *outEvents = pending.events; if (outData != NULL) *outData = pending.data; } else { @@ -268,16 +270,20 @@ bool PollLoop::getAllowNonCallbacks() const { return mAllowNonCallbacks; } +void PollLoop::setCallback(int fd, int ident, int events, Callback callback, void* data) { + setCallbackCommon(fd, ident, events, callback, NULL, data); +} + void PollLoop::setCallback(int fd, int events, Callback callback, void* data) { - setCallbackCommon(fd, events, callback, NULL, data); + setCallbackCommon(fd, POLL_CALLBACK, events, callback, NULL, data); } -void PollLoop::setLooperCallback(int fd, int events, ALooper_callbackFunc* callback, +void PollLoop::setLooperCallback(int fd, int ident, int events, ALooper_callbackFunc* callback, void* data) { - setCallbackCommon(fd, events, NULL, callback, data); + setCallbackCommon(fd, ident, events, NULL, callback, data); } -void PollLoop::setCallbackCommon(int fd, int events, Callback callback, +void PollLoop::setCallbackCommon(int fd, int ident, int events, Callback callback, ALooper_callbackFunc* looperCallback, void* data) { #if DEBUG_CALLBACKS @@ -305,6 +311,7 @@ void PollLoop::setCallbackCommon(int fd, int events, Callback callback, RequestedCallback requestedCallback; requestedCallback.callback = callback; requestedCallback.looperCallback = looperCallback; + requestedCallback.ident = ident; requestedCallback.data = data; ssize_t index = getRequestIndexLocked(fd); -- cgit v1.2.3-59-g8ed1b