In Android NDK, what is the difference between ALooper_pollOnce()
and ALooper_pollAll()
?
These simple specify how many (maximum) callbacks to process from Looper's event queue. As names suggest, pollAll()
executes all callbacks from the event queue until the data event, error or timeout is encountered. On the other hand, pollOnce()
returns ALOOPER_POLL_CALLBACK as soon as first callback is executed.
Basically, their relationship can be expressed in the following pseudocode:
int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData) {
int result;
do {
result = ALooper_pollOnce(timeoutMillis, outFd, outEvents, outData);
} while (result == ALOOPER_POLL_CALLBACK);
return result;
}
ALooper_pollAll
should not be used (in fact, it's currently marked as removed in AOSP, so it won't be callable soon). There's a bug in ALooper_pollAll
that means it may not respond to ALooper_wake
. The issues are explained in detail at https://github.com/android/ndk/discussions/2020.
The intended difference between the two was for ALooper_pollAll
to not return control to the caller until it received an event not handled by a callback (such as a legitimate event that did not have a callback registered, an error, or an explicit wake), whereas ALooper_pollOnce
would return after handling the first event, callback or otherwise.
© 2022 - 2024 — McMap. All rights reserved.