Re: Synchronous signal delivery..

Daniel Heater
2003-02-17T15:16:57Z

* Davide Libenzi (davidel@xmailserver.org) wrote:
> On Thu, 13 Feb 2003, Linus Torvalds wrote:
>
> > > > One of the reasons for the "flags" field (which is not unused) was because
> > > > I thought it might have extensions for things like alarms etc.
> > >
> > > I was thinking more like :
> > >
> > > int timerfd(int timeout, int oneshot);
> >
> > It could be a separate system call, ...
>
> I would personally like it a lot to have timer events available on
> pollable fds. Am I alone in this ?

I currently do something similar to this with a driver for an 82c54 timer,
and for a couple of of hardware timer implementations.

I create a fd for each timer in the device. write() sets the timer count.
read() reads back the current timer count. select() with the timer's fd
as the exceptionfd argument is used to poll for a timer expiration. With
this hardware, the count is automatically reloaded and continues counting.

With this interface, I can write a simple app that waits for any number of
events on file descriptors using select, but will also timeout periodically
to do some housekeeping data. I just switch on the file descriptor when I
come out of the select to decide what needs to be done.

This seems simpler to me in many cases where I can allow some drift in doing
the timeout housekeeping because the rest of the code need not be concerned
with getting preempted by a signal. ie. No need to lock data structures
because there is always only one thread of control.

daniel.