From 888a748bf23f7afb19c026d96245b31ca0abdd15 Mon Sep 17 00:00:00 2001 From: Spencer Low Date: Tue, 29 Sep 2015 18:33:38 -0700 Subject: [PATCH] adb: fdevent fixes * fdevent_{set,add,del}() * CHECK() that the fdevent is FDE_ACTIVE, otherwise the caller would be waiting for events that will never arrive. * Remove ~ from "fde->events &= ~events" to keep desired bits instead of turning off desired bits. * fdevent_call_fdfunc() * CHECK(FDE_PENDING) since it should always be true if the fdevent was on the pending list, or if fdevent_subproc_event_func() is faking things. The goal is to try to avoid losing events. Change-Id: I979c2fffa0b3d6b635488cde11dc544691193018 Signed-off-by: Spencer Low --- adb/fdevent.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/adb/fdevent.cpp b/adb/fdevent.cpp index 2ffd908d4..1ccee9be9 100644 --- a/adb/fdevent.cpp +++ b/adb/fdevent.cpp @@ -174,17 +174,16 @@ void fdevent_set(fdevent* fde, unsigned events) { if ((fde->state & FDE_EVENTMASK) == events) { return; } - if (fde->state & FDE_ACTIVE) { - fdevent_update(fde, events); - D("fdevent_set: %s, events = %u", dump_fde(fde).c_str(), events); + CHECK(fde->state & FDE_ACTIVE); + fdevent_update(fde, events); + D("fdevent_set: %s, events = %u", dump_fde(fde).c_str(), events); - if (fde->state & FDE_PENDING) { - // If we are pending, make sure we don't signal an event that is no longer wanted. - fde->events &= ~events; - if (fde->events == 0) { - g_pending_list.remove(fde); - fde->state &= ~FDE_PENDING; - } + if (fde->state & FDE_PENDING) { + // If we are pending, make sure we don't signal an event that is no longer wanted. + fde->events &= events; + if (fde->events == 0) { + g_pending_list.remove(fde); + fde->state &= ~FDE_PENDING; } } } @@ -262,7 +261,7 @@ static void fdevent_call_fdfunc(fdevent* fde) { unsigned events = fde->events; fde->events = 0; - if(!(fde->state & FDE_PENDING)) return; + CHECK(fde->state & FDE_PENDING); fde->state &= (~FDE_PENDING); D("fdevent_call_fdfunc %s", dump_fde(fde).c_str()); fde->func(fde->fd, events, fde->arg);