As far as I know, file descriptors are local to processes and inherently
shared by all threads in the same process

On Thu, Apr 2, 2009 at 6:48 PM, Huaka‘i Po <[email protected]> wrote:

>
> I was guessing that was the case.  Thanks for the confirmation.  But
> because the original fd returned by getDataChanel is used to create an
> instance of  ParcelFileDescriptor (mSensorDataFd) before the event
> handling thread is spawned, does anything happen behind the scenes to
> make the descriptor local to that thread?  I'm asking both because in
> sensors.h there's a comment 'The caller takes ownership of this fd.
> This is intended to be passed cross processes.' (referring to
> open_data_source) and because if the descriptor isn't made thread-
> local by the Parcel code, I don't see why one would use a
> ParcelFileDescriptor instance in the first place.
>
> Further, the event handler thread closes mSensorDataFd.  The event
> handler thread dies every time there are no more listeners.
> Registering a new listener would then cause a new handler thread to
> get spawned.  That will call getDataChanel again.  So the really I'm
> asking whether getDataChanel has to open the device again, or whether
> it can just open it once over the life of the SensorManager process?
>
> On Apr 2, 12:10 am, pixelflinger <[email protected]> wrote:
> > 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-level sensor api from Java.
> >
> > Mathias
> >
> > On Wed, Apr 1, 2009 at 4:26 PM, Huaka‘i Po <[email protected]>
> wrote:
> >
> > > (reposting from android-framework)
> > > Hi all,
> > > is the file descriptor in SensorManager.java global to all threads?
> >
> > > In setting up the event dispatch thread for sensor events, there is a
> > > call
> > > ParcelFileDescriptor fd = service.getDataChanel();
> > > getDataChanel() eventually winds up calling open_data_source in the
> > > sensor framework, 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
> >
>

--~--~---------~--~----~------------~-------~--~----~
unsubscribe: [email protected]
website: http://groups.google.com/group/android-porting
-~----------~----~----~----~------~----~------~--~---

Reply via email to