Loading include/utils/PollLoop.h +11 −3 Original line number Diff line number Diff line Loading @@ -111,12 +111,18 @@ public: * This method can be called on any thread. * This method may block briefly if it needs to wake the poll loop. */ void setCallback(int fd, int ident, int events, Callback callback, void* data = NULL); /** * Convenience for above setCallback when ident is not used. In this case * the ident is set to POLL_CALLBACK. */ void setCallback(int fd, int events, Callback callback, void* data = NULL); /** * Like setCallback(), but for the NDK callback function. */ void setLooperCallback(int fd, int events, ALooper_callbackFunc* callback, void setLooperCallback(int fd, int ident, int events, ALooper_callbackFunc* callback, void* data); /** Loading Loading @@ -153,11 +159,13 @@ private: struct RequestedCallback { Callback callback; ALooper_callbackFunc* looperCallback; int ident; void* data; }; struct PendingCallback { int fd; int ident; int events; Callback callback; ALooper_callbackFunc* looperCallback; Loading Loading @@ -185,7 +193,7 @@ private: void openWakePipe(); void closeWakePipe(); void setCallbackCommon(int fd, int events, Callback callback, void setCallbackCommon(int fd, int ident, int events, Callback callback, ALooper_callbackFunc* looperCallback, void* data); ssize_t getRequestIndexLocked(int fd); void wakeAndLock(); Loading libs/gui/SensorEventQueue.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -86,7 +86,7 @@ sp<PollLoop> SensorEventQueue::getPollLoop() const Mutex::Autolock _l(mLock); if (mPollLoop == 0) { mPollLoop = new PollLoop(true); mPollLoop->setCallback(getFd(), POLLIN, NULL, NULL); mPollLoop->setCallback(getFd(), getFd(), POLLIN, NULL, NULL); } return mPollLoop; } Loading libs/utils/PollLoop.cpp +13 −6 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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(); Loading Loading @@ -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; Loading @@ -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 { Loading Loading @@ -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 Loading Loading @@ -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); Loading libs/utils/Threads.cpp +31 −8 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include <utils/Log.h> #include <cutils/sched_policy.h> #include <cutils/properties.h> #include <stdio.h> #include <stdlib.h> Loading Loading @@ -57,7 +58,7 @@ using namespace android; // ---------------------------------------------------------------------------- /* * Create and run a new thead. * Create and run a new thread. * * We create it "detached", so it cleans up after itself. */ Loading Loading @@ -280,6 +281,22 @@ pid_t androidGetTid() #endif } #if defined(HAVE_PTHREADS) static pthread_once_t gDoSchedulingGroupOnce = PTHREAD_ONCE_INIT; static bool gDoSchedulingGroup = true; static void checkDoSchedulingGroup(void) { char buf[PROPERTY_VALUE_MAX]; int len = property_get("debug.sys.noschedgroups", buf, ""); if (len > 0) { int temp; if (sscanf(buf, "%d", &temp) == 1) { gDoSchedulingGroup = temp == 0; } } } #endif int androidSetThreadSchedulingGroup(pid_t tid, int grp) { if (grp > ANDROID_TGROUP_MAX || grp < 0) { Loading @@ -287,10 +304,13 @@ int androidSetThreadSchedulingGroup(pid_t tid, int grp) } #if defined(HAVE_PTHREADS) pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup); if (gDoSchedulingGroup) { if (set_sched_policy(tid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ? SP_BACKGROUND : SP_FOREGROUND)) { return PERMISSION_DENIED; } } #endif return NO_ERROR; Loading @@ -303,11 +323,14 @@ int androidSetThreadPriority(pid_t tid, int pri) #if defined(HAVE_PTHREADS) int lasterr = 0; pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup); if (gDoSchedulingGroup) { if (pri >= ANDROID_PRIORITY_BACKGROUND) { rc = set_sched_policy(tid, SP_BACKGROUND); } else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) { rc = set_sched_policy(tid, SP_FOREGROUND); } } if (rc) { lasterr = errno; Loading libs/utils/ZipFileRO.cpp +5 −9 Original line number Diff line number Diff line Loading @@ -636,7 +636,7 @@ bool ZipFileRO::uncompressEntry(ZipEntryRO entry, void* buffer) const memcpy(buffer, ptr, uncompLen); } else { if (!inflateBuffer(buffer, ptr, uncompLen, compLen)) goto unmap; goto bail; } if (compLen > kSequentialMin) Loading @@ -644,8 +644,6 @@ bool ZipFileRO::uncompressEntry(ZipEntryRO entry, void* buffer) const result = true; unmap: file->release(); bail: return result; } Loading @@ -669,7 +667,7 @@ bool ZipFileRO::uncompressEntry(ZipEntryRO entry, int fd) const getEntryInfo(entry, &method, &uncompLen, &compLen, &offset, NULL, NULL); FileMap* file = createEntryFileMap(entry); const FileMap* file = createEntryFileMap(entry); if (file == NULL) { goto bail; } Loading @@ -680,23 +678,21 @@ bool ZipFileRO::uncompressEntry(ZipEntryRO entry, int fd) const ssize_t actual = write(fd, ptr, uncompLen); if (actual < 0) { LOGE("Write failed: %s\n", strerror(errno)); goto unmap; goto bail; } else if ((size_t) actual != uncompLen) { LOGE("Partial write during uncompress (%zd of %zd)\n", (size_t)actual, (size_t)uncompLen); goto unmap; goto bail; } else { LOGI("+++ successful write\n"); } } else { if (!inflateBuffer(fd, ptr, uncompLen, compLen)) goto unmap; goto bail; } result = true; unmap: file->release(); bail: return result; } Loading Loading
include/utils/PollLoop.h +11 −3 Original line number Diff line number Diff line Loading @@ -111,12 +111,18 @@ public: * This method can be called on any thread. * This method may block briefly if it needs to wake the poll loop. */ void setCallback(int fd, int ident, int events, Callback callback, void* data = NULL); /** * Convenience for above setCallback when ident is not used. In this case * the ident is set to POLL_CALLBACK. */ void setCallback(int fd, int events, Callback callback, void* data = NULL); /** * Like setCallback(), but for the NDK callback function. */ void setLooperCallback(int fd, int events, ALooper_callbackFunc* callback, void setLooperCallback(int fd, int ident, int events, ALooper_callbackFunc* callback, void* data); /** Loading Loading @@ -153,11 +159,13 @@ private: struct RequestedCallback { Callback callback; ALooper_callbackFunc* looperCallback; int ident; void* data; }; struct PendingCallback { int fd; int ident; int events; Callback callback; ALooper_callbackFunc* looperCallback; Loading Loading @@ -185,7 +193,7 @@ private: void openWakePipe(); void closeWakePipe(); void setCallbackCommon(int fd, int events, Callback callback, void setCallbackCommon(int fd, int ident, int events, Callback callback, ALooper_callbackFunc* looperCallback, void* data); ssize_t getRequestIndexLocked(int fd); void wakeAndLock(); Loading
libs/gui/SensorEventQueue.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -86,7 +86,7 @@ sp<PollLoop> SensorEventQueue::getPollLoop() const Mutex::Autolock _l(mLock); if (mPollLoop == 0) { mPollLoop = new PollLoop(true); mPollLoop->setCallback(getFd(), POLLIN, NULL, NULL); mPollLoop->setCallback(getFd(), getFd(), POLLIN, NULL, NULL); } return mPollLoop; } Loading
libs/utils/PollLoop.cpp +13 −6 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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(); Loading Loading @@ -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; Loading @@ -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 { Loading Loading @@ -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 Loading Loading @@ -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); Loading
libs/utils/Threads.cpp +31 −8 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include <utils/Log.h> #include <cutils/sched_policy.h> #include <cutils/properties.h> #include <stdio.h> #include <stdlib.h> Loading Loading @@ -57,7 +58,7 @@ using namespace android; // ---------------------------------------------------------------------------- /* * Create and run a new thead. * Create and run a new thread. * * We create it "detached", so it cleans up after itself. */ Loading Loading @@ -280,6 +281,22 @@ pid_t androidGetTid() #endif } #if defined(HAVE_PTHREADS) static pthread_once_t gDoSchedulingGroupOnce = PTHREAD_ONCE_INIT; static bool gDoSchedulingGroup = true; static void checkDoSchedulingGroup(void) { char buf[PROPERTY_VALUE_MAX]; int len = property_get("debug.sys.noschedgroups", buf, ""); if (len > 0) { int temp; if (sscanf(buf, "%d", &temp) == 1) { gDoSchedulingGroup = temp == 0; } } } #endif int androidSetThreadSchedulingGroup(pid_t tid, int grp) { if (grp > ANDROID_TGROUP_MAX || grp < 0) { Loading @@ -287,10 +304,13 @@ int androidSetThreadSchedulingGroup(pid_t tid, int grp) } #if defined(HAVE_PTHREADS) pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup); if (gDoSchedulingGroup) { if (set_sched_policy(tid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ? SP_BACKGROUND : SP_FOREGROUND)) { return PERMISSION_DENIED; } } #endif return NO_ERROR; Loading @@ -303,11 +323,14 @@ int androidSetThreadPriority(pid_t tid, int pri) #if defined(HAVE_PTHREADS) int lasterr = 0; pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup); if (gDoSchedulingGroup) { if (pri >= ANDROID_PRIORITY_BACKGROUND) { rc = set_sched_policy(tid, SP_BACKGROUND); } else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) { rc = set_sched_policy(tid, SP_FOREGROUND); } } if (rc) { lasterr = errno; Loading
libs/utils/ZipFileRO.cpp +5 −9 Original line number Diff line number Diff line Loading @@ -636,7 +636,7 @@ bool ZipFileRO::uncompressEntry(ZipEntryRO entry, void* buffer) const memcpy(buffer, ptr, uncompLen); } else { if (!inflateBuffer(buffer, ptr, uncompLen, compLen)) goto unmap; goto bail; } if (compLen > kSequentialMin) Loading @@ -644,8 +644,6 @@ bool ZipFileRO::uncompressEntry(ZipEntryRO entry, void* buffer) const result = true; unmap: file->release(); bail: return result; } Loading @@ -669,7 +667,7 @@ bool ZipFileRO::uncompressEntry(ZipEntryRO entry, int fd) const getEntryInfo(entry, &method, &uncompLen, &compLen, &offset, NULL, NULL); FileMap* file = createEntryFileMap(entry); const FileMap* file = createEntryFileMap(entry); if (file == NULL) { goto bail; } Loading @@ -680,23 +678,21 @@ bool ZipFileRO::uncompressEntry(ZipEntryRO entry, int fd) const ssize_t actual = write(fd, ptr, uncompLen); if (actual < 0) { LOGE("Write failed: %s\n", strerror(errno)); goto unmap; goto bail; } else if ((size_t) actual != uncompLen) { LOGE("Partial write during uncompress (%zd of %zd)\n", (size_t)actual, (size_t)uncompLen); goto unmap; goto bail; } else { LOGI("+++ successful write\n"); } } else { if (!inflateBuffer(fd, ptr, uncompLen, compLen)) goto unmap; goto bail; } result = true; unmap: file->release(); bail: return result; } Loading