Thanks. These replies and some more digging on my own helped me figure out what I needed. Probably the most critical point I didn't realize at first was that getDataChanel does some IPC stuff under the covers to get a descriptor sent across process boundaries. (I originally thought everything was happening in a single process.) For anyone else running in to this, the fd returned by open_data_source gets fed back from the sensor service to the requesting process. Then sensor service closes it for the system_server process. The fd in the receiving process is global to the process, so any thread closing it closes it for all.
On Apr 2, 12:44 am, pixelflinger <[email protected]> wrote: > Hi, > > I'm not completely sure about what you're asking, so I'll do my best > to answer :-) > > There is only one thread per process handling the events. Note that > there should only be one instance of SensorManager as well (it's a > singleton). > > It's therefore not possible to have more than one thread per process > using the low-levelsensorapi from Java. > > Now to answer your question literally, yes, the filedescriptor is the > same in both threads, therefore it gets closed when the thread > returns. But notice that getDataChanel() is called again when the > thread is re-started. > > getDataChanel() gives ownership of the fd to the caller (conceptually > it does a "dup" before returning it). > > Hope this helps. > > Mathias > > On Apr 1, 4:10 pm, Huaka‘i Po <[email protected]> wrote: > > > Hi all, > > is the file descriptor in SensorManager.java global to all threads? > > > In setting up the event dispatch thread forsensorevents, there is a > > call > > ParcelFileDescriptor fd = service.getDataChanel(); > > getDataChanel() eventually winds up calling open_data_source in the > >sensorframework, which returns an open Linux fd. Then the code > > instantiates a new thread with a SensorThreadRunnable, part of which > > is here: > > > private class SensorThreadRunnable implements Runnable { > > private ParcelFileDescriptor mSensorDataFd; > > SensorThreadRunnable(ParcelFileDescriptor fd) { > > mSensorDataFd = fd; > > } > > ... > > > The run() method of SensorThreadRunnable later closes mSensorDataFd. > > Does that close the original fd returned by getDataChanel? (i.e. is > > the fd the same one in both threads, or are the semantics more like dup > > () because of the Parcel stuff?) > > > Thanks, > > Hod --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "android-framework" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-framework?hl=en -~----------~----~----~----~------~----~------~--~---
