Android NDK ALooper_pollOnce() vs ALooper_pollAll()
Asked Answered
N

2

5

In Android NDK, what is the difference between ALooper_pollOnce() and ALooper_pollAll()?

Normalie answered 23/12, 2015 at 6:6 Comment(0)
S
7

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;
}
Sidhu answered 23/1, 2016 at 8:27 Comment(0)
C
0

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.

Cognac answered 2/5 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.