Poll with zero or negative timeout
Joakim Tjernlund
joakim.tjernlund at transmode.se
Tue Oct 23 08:59:47 UTC 2007
On Tue, 2007-10-23 at 08:42 +0200, Jean-Christian de Rivaz wrote:
> Hello,
>
> I tried to use the bug tracking system, but the "Report Issue" page
> never go after the "Select Project" form. So I post this patch here.
>
> The attached patch solve an issue I faced while using the libdbus-glib
> waiting for a D-Bus message or the end of a glib timer at the same time.
> This specific case of use generate a poll call with a zero timeout. On
> platformes with the glibc a zero timeout poll return immetiately even if
> there is no file descriptor event. But on platformes with uClibc a zero
> timeout poll block until a file descriptor event occurs.
>
> I found that the file libc/sysdeps/linux/common/poll.c only take care of
> positive timeout and pass a null pointer in case of a zero or negative
> timeout, making the zero and negative the same case: blocking.
>
> The patch alway pass a valid structure for the timeout of poll and
> assign acceptable timeout values for the zero and negative case by
> avoiding the math needed for positive timeout value.
>
> This has been tested on a Blackfin BF533 processor.
>
> Have a good day,
> --
> Jean-Christian de Rivaz
> plain text document attachment (poll-zero-or-negative-timeout.txt)
> Index: libc/sysdeps/linux/common/poll.c
> ===================================================================
> --- libc/sysdeps/linux/common/poll.c (revision 20316)
> +++ libc/sysdeps/linux/common/poll.c (working copy)
> @@ -37,8 +37,14 @@
> if (timeout > 0) {
> tval.tv_sec = timeout / 1000;
> tval.tv_nsec = (timeout % 1000) * 1000000;
> - ts = &tval;
> + } else if (timeout == 0) {
> + tval.tv_sec = 0;
> + tval.tv_nsec = 0;
> + } else {
> + tval.tv_sec = -1;
> + tval.tv_nsec = 0;
> }
> + ts = &tval;
> return ppoll(fds, nfds, ts, NULL);
> }
can't you just do:
if (timeout >= 0) {
tval.tv_sec = timeout / 1000;
tval.tv_nsec = (timeout % 1000) * 1000000;
ts = &tval;
or is the timeout=0 case performance sensitive?
And why not pass NULL as it was before?
} else {
tval.tv_sec = -1; /* ~0 instead ? */
tval.tv_nsec = 0;
}
ts = &tval;
More information about the uClibc
mailing list