[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows

From: Derek Robert Price
Subject: Re: [Bug-gnulib] Re: GNULib Module gettime Breaks CVS Build On Windows
Date: Sun, 16 May 2004 15:17:16 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413

Hash: SHA1

Paul Eggert wrote:

>Derek Robert Price <address@hidden> writes:
>>I've also added my_usleep & nanosleep functions to
>>windows-NT/woe32.c.  They are mostly duplicated code from nanosleep.c,
>>so I'm tempted to fork our nanosleep.c to include the #include
>><winsock.h> instead and ease maintenence, but it's somewhat debatable
>>whether that is easier since it would complicate updates from GNULIB.
>I'd like to mention a couple of things about gnulib nanosleep.
>First, the gnulib nanosleep isn't a complete replacement for
>nanosleep.  It might not sleep long enough (even when not
>interrupted), due to limitations in the underlying primitives.  Also,
>it returns garbage in its 2nd arg.  coreutils (the only other user of
>gnulib nanosleep, as far as I know) is immune to both of these
>problems, since it uses a wrapper (called xnanosleep) that works
>around them.  Is CVS similar?  If not, perhaps xnanosleep should be
>added to gnulib, and CVS should use that.  (Note that many versions of
>the Linux kernel return garbage in nanosleep's 2nd arg, so something
>like xnanosleep is necessary for them too....)

CVS is using nanosleep but not its second arg.  This is a carryover
from the fact that CVS's configure used to detect the finest grained sleep
function it could find (nanosleep, usleep, or select) and then fall
back on sleep if all else failed.  Since nanosleep was the only one
that returned unslept time, CVS used repeated calls to time &
gettimeofday to determine if it had slept long enough yet and
determine how much longer to sleep, When I added the GNULIB nanosleep
module, I didn't update the code to try and use the second arg to
nanosleep as more efficient. simply because I hadn't noticed it yet.

I assume that xnanosleep is doing something similar (repeated calls to
time or gettime or whatever), but it might make sense to import &
share xnanosleep due to the various advantages of having shared code.
(I just looked at xnanosleep.c and yes, it looks very similar to CVS's
sleep_until function except that sleep_until takes an absolute time_t
UNIX time (seconds since the epoch) and stays under until that time is

Would it be worthwhile to test for whether the second arg appears to
contain a garbage return via nanosleep.m4 and move the switched
gettime wrapper functionality into nanosleep.m4 itself?  I would
assume an alarm (1 second), nanosleep (5 seconds), check 2nd arg value
is close to 4 seconds would do the trick?  I could write such a thing
fairly quickly.

>Second, if the only reason CVS is using nanosleep is to have a
>fine-grained sleep, and if the Windows platform has a usleep function
>compatible with POSIX's obsolescent usleep API
>then it wouldn't be hard to add support for that to gnulib nanosleep,
>so that gnulib nanosleep would use sleep+usleep if available.

No, Windows does not have such a beast.  I mistakenly told Conrad it
did since CVS was defining HAVE_USLEEP in the windows-NT/config.h, but
it turned out that it was actually implemented in the CVS
windows-NT/woe32.c file using the Windows Sleep function.

>PS.  I don't see gnulib nanosleep.c in CVS 1.12.7 so I'm a bit lost as
>to where CVS is using it.

I just recently noticed it and imported it while importing perquisites of
getdate.y for the 1.12.8 release (on Wednesday if everything goes as
planned).  I had to back out the getdate.y import re our other recent
thread, but the nanosleep.c file should be in the 1.12.8 release.

>PPS.  POSIX says that one must include <sys/select.h> before using
>select so I guess gnulib nanosleep.c should have that change
>regardless of the other changes being discussed.

That's fine by me, but it won't solve the Windows problem,
unfortunately.  The simplest solution we've found so far is to have
nanosleep.c include winsock.h to enable the Windows select function.
Alternately, it could declare the select prototype and the struct
timeval when !HAVE_<needed_headers>, but that seems more complicated
to me.



- --

Email: address@hidden

Get CVS support at <http://ximbiot.com>!
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]