Author: eliot Date: 2010-08-13 14:14:21 -0700 (Fri, 13 Aug 2010) New Revision: 2253 Modified: branches/Cog/platforms/unix/vm/sqUnixHeartbeat.c Log: Integrate Henrik Johansen's fix for the nanosleep call in the heartbeat. Modified: branches/Cog/platforms/unix/vm/sqUnixHeartbeat.c =================================================================== --- branches/Cog/platforms/unix/vm/sqUnixHeartbeat.c 2010-08-11 18:03:02 UTC (rev 2252) +++ branches/Cog/platforms/unix/vm/sqUnixHeartbeat.c 2010-08-13 21:14:21 UTC (rev 2253) @@ -607,6 +607,8 @@ struct timespec naptime = beatperiod; while (nanosleep(&naptime, &naptime) == -1 + /* oversleeps can return tv_sec = -1 tv_nsec approx 999999999 */ + && naptime.tv_sec >= 0 /* avoid undoc'ed oversleep behaviour */ && (naptime.tv_sec > 0 || naptime.tv_nsec > MINSLEEPNS)) /*repeat*/ if (errno != EINTR) { perror("nanosleep"); |
To be finicky, it's not actually undocumented though, if I interpreted the man pages correctly :)Author: eliot Date: 2010-08-13 14:14:21 -0700 (Fri, 13 Aug 2010) New Revision: 2253 Modified: branches/Cog/platforms/unix/vm/sqUnixHeartbeat.c Log: Integrate Henrik Johansen's fix for the nanosleep call in the heartbeat. Modified: branches/Cog/platforms/unix/vm/sqUnixHeartbeat.c =================================================================== --- branches/Cog/platforms/unix/vm/sqUnixHeartbeat.c 2010-08-11 18:03:02 UTC (rev 2252) +++ branches/Cog/platforms/unix/vm/sqUnixHeartbeat.c 2010-08-13 21:14:21 UTC (rev 2253) @@ -607,6 +607,8 @@ struct timespec naptime = beatperiod; while (nanosleep(&naptime, &naptime) == -1 + /* oversleeps can return tv_sec = -1 tv_nsec approx 999999999 */ + && naptime.tv_sec >= 0 /* avoid undoc'ed oversleep behaviour */ && (naptime.tv_sec > 0 || naptime.tv_nsec > MINSLEEPNS)) /*repeat*/ if (errno != EINTR) { perror("nanosleep"); http://www.opengroup.org/onlinepubs/009695399/functions/nanosleep.html http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man2/nanosleep.2.html "If the rmtp argument is non-NULL, thetimespec structure referenced by it is updated to contain the amount of time remaining in the interval (the requested time minus the time actually slept). " Since it also specifies that the valid range for tv_nsec is 0 - 999999999, a negative value for tv_sec is the only valid option when it has overslept before being interrupted. Cheers, Henry |
Hi Henrik, On Fri, Aug 13, 2010 at 2:56 PM, Henrik Sperre Johansen <[hidden email]> wrote:
You're right. When I speed-read "If rmtp is non-NULL, the timespec structure it references is updated to contain the unslept amount (the request time minus the time actually slept)." I ignored "the request time minus the time actually slept" and assumed it would not return a negative amount. I'll change the code.
thanks again, Eliot
|
Free forum by Nabble | Edit this page |