fix an issue where invalidate/transactions could be missed
Change-Id: I84a1fcba1317b2631f5441de7b7ecd12af5ad022
This commit is contained in:
parent
2228936411
commit
be42aef82f
@ -44,7 +44,7 @@ void MessageBase::handleMessage(const Message&) {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
MessageQueue::MessageQueue()
|
MessageQueue::MessageQueue()
|
||||||
: mLooper(new Looper(true))
|
: mLooper(new Looper(true)), mWorkPending(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,11 +58,11 @@ void MessageQueue::waitMessage() {
|
|||||||
int32_t ret = mLooper->pollOnce(-1);
|
int32_t ret = mLooper->pollOnce(-1);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case ALOOPER_POLL_WAKE:
|
case ALOOPER_POLL_WAKE:
|
||||||
// we got woken-up there is work to do in the main loop
|
|
||||||
return;
|
|
||||||
|
|
||||||
case ALOOPER_POLL_CALLBACK:
|
case ALOOPER_POLL_CALLBACK:
|
||||||
// callback was handled, loop again
|
// callback and/or wake
|
||||||
|
if (android_atomic_and(0, &mWorkPending)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case ALOOPER_POLL_TIMEOUT:
|
case ALOOPER_POLL_TIMEOUT:
|
||||||
@ -94,7 +94,9 @@ status_t MessageQueue::postMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
status_t MessageQueue::invalidate() {
|
status_t MessageQueue::invalidate() {
|
||||||
mLooper->wake();
|
if (android_atomic_or(1, &mWorkPending) == 0) {
|
||||||
|
mLooper->wake();
|
||||||
|
}
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ private:
|
|||||||
|
|
||||||
class MessageQueue {
|
class MessageQueue {
|
||||||
sp<Looper> mLooper;
|
sp<Looper> mLooper;
|
||||||
|
volatile int32_t mWorkPending;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MessageQueue();
|
MessageQueue();
|
||||||
|
Loading…
Reference in New Issue
Block a user