Commit graph

15 commits

Author SHA1 Message Date
Tim Kilbourn
8892ce6383 Use eventfd instead of pipe in Looper.
Bug: 19933224
Change-Id: I6611e918db960bbb0e74f8308e10bdf79510b899
2015-03-27 09:15:43 -07:00
Jeff Brown
e7d54f80cb Fix issues related to removing Looper callbacks after close.
When a file descriptor is closed before removing it from the
epoll set, it will normally be removed automatically from the
epoll set by the kernel.  However if there exists a duplicate
then the original file descriptor may remain in the set and
continue to receive events until all duplicates have been closed.

Unfortunately due to kernel limitations we need to rebuild the epoll
set from scratch because it may contain an old file handle that we are
now unable to remove since its file descriptor is no longer valid.
No such problem would have occurred if we were using the poll system
call instead, but that approach carries others disadvantages.

Bug: 19715279
Change-Id: If1ab8ebda0825755a416d513e888942a02ee3948
2015-03-12 19:44:49 -07:00
Jeff Brown
7a0310ef67 Fixed subtle bugs related to file descriptor recycling.
Added code to protect against situations that may occur when a
Looper callback has the side-effect of closing the file descriptor that
it is watching before it returns.  This code pattern is very
convenient for implementation but it does expose issues in how
the list of callbacks is maintained.  In particular, we
need to watch out for file descriptors which have been reused.

This change may resolve previously unexplained ANRs associated with
log messages such as: "Error modifying epoll events for fd 44, errno=2"

Bug: 10349083
Change-Id: I20eedf6ffbdeda382653ca0104962505194741b0
2015-03-11 15:00:36 -07:00
Jeff Brown
27e5721860 Rename Looper::isIdling() to isPolling() to resolve confusion.
The loop isn't technically idle at this time, it's just checking
whether any file descriptors have pending events.  However it's
still a good signal as to whether the loop is alive.

Bug: 19532373
Change-Id: I555c473e70ffd8a56e1b10aa60026eb674a16de9
2015-03-11 15:00:36 -07:00
Brian Carlstrom
1693d7e48f Make libutils Looper independent of frameworks/native
Change-Id: I1dacca10a3cd7601abc3451b69ed761bf71c38fe
2013-12-18 22:32:13 -08:00
Dianne Hackborn
19159f9002 Add new Looper API to check whether the looper is idle.
This is just to support the watchdog to give it a faster
way to determine if a thread is deadlocked without having
to post a message to it.

Change-Id: I068dc8b9387caf94fe5811fb4aeb0f9b57b1a080
2013-07-30 13:57:01 -07:00
Jeff Brown
dd1b0378ce Support looper callbacks based on smart pointers.
Bug: 6559630
Change-Id: I5a667f219f431838638acefbc9fa6afa610971bd
2013-07-30 13:56:59 -07:00
Jeff Brown
5705e69825 Delete unused poll() code.
We don't need this code anymore and it is just in the way.

Bug: 6559630
Change-Id: I1dc9decf85d5ea1feab159c2985da6c20baffdd5
2013-07-30 13:56:59 -07:00
Jeff Brown
55195d745c Remove unused statistics code.
Bug: 6559630
Change-Id: Iacdf4bb4c1c125c09305cbd8cb443c7c80cfc010
2013-07-30 13:56:59 -07:00
Jeff Brown
3e2e38bc5b Fade out the mouse pointer after inactivity or other events.
Fades out the mouse pointer:
- after 15 seconds of inactivity normally
- after 3 seconds of inactivity in lights out mode
- after a non-modifier key down
- after a touch down

Extended the native Looper to support enqueuing time delayed
messages.  This is used by the PointerController to control
pointer fade timing.

Change-Id: I87792fea7dbe2d9376c78cf354fe3189a484d9da
2013-07-30 13:56:56 -07:00
Jeff Brown
fcefac2682 Revert to using epoll_wait().
This change depends on the kernel having been patched to use hrtimers
instead of jiffies for scheduling epoll timeouts.

Change-Id: I216bc1c4f565e67ebcb3d2ba4280cb615932bb9e
2013-07-30 13:56:55 -07:00
Jeff Brown
8d15c74d50 Switch Looper back to using poll() instead of epoll().
Added a couple of micro-optimizations to avoid calling wake() unnecessarily
and reduce JNI overhead slightly.

Fixed a minor issue where we were not clearing the "next" field of Messages
returned by the MessageQueue so the Message would hold on to its successor
and potentially prevent the GC from collecting it if the message were leaked
somehow.

Change-Id: I488d29417ce0cdd7d0e447cda76ec978ef7f811c
2013-07-30 13:56:55 -07:00
Jeff Brown
d18051870e Looper: use pthread_once for TLS key initialization.
Also fix a Valgrind complaint by zeroing out the entire epoll event
struct since otherwise the data field union would be partly
uninitialized (but not in a harmful way).

Change-Id: I2091ce517e87fcad7c9caf90e2c5e4854a7ca465
2013-07-30 13:56:54 -07:00
Jeff Brown
905682a196 Looper: Drop default parameters in favor of a safer overload.
The idea is that if you're writing code that wants fd/events/data on
return from pollOnce() / pollAll() you should really pass in all of those
arguments.  When I changed the Looper API earlier, it was difficult
to ensure that all callers were passing the right parameters since they
were relying on default parameters to some degree so usage mistakes
would not have been caught by the compiler.

Change-Id: I1f2812894270aaf1515017ac1616b6b312d9b565
2013-07-30 13:56:54 -07:00
Jeff Brown
7901eb25c6 Replace epoll() with poll() and rename PollLoop to Looper.
As part of this change, consolidated and cleaned up the Looper API so
that there are fewer distinctions between the NDK and non-NDK declarations
(no need for two callback types, etc.).

Removed the dependence on specific constants from sys/poll.h such as
POLLIN.  Instead looper.h defines events like LOOPER_EVENT_INPUT for
the events that it supports.  That should help make any future
under-the-hood implementation changes easier.

Fixed a couple of compiler warnings along the way.

Change-Id: I449a7ec780bf061bdd325452f823673e2b39b6ae
2013-07-30 13:56:54 -07:00