This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: setitimer with values less than 1000 microseconds


On Mon, Jun 26, 2000 at 04:24:42PM -0400, Ashif S. Harji wrote:
>It simply hangs unless I use a timer value of 1000 microseconds or higher. 
>When I run this program on a linux or sun sparc machine, it works fine. 
>The difference seems to be that on these machines the timer value is
>rounded up to the nearest resolution value.  However, with cygwin the
>values are rounded down.  That is in the source code for setitimer in
>window.cc: 
>
>  elapse = itv.it_value.tv_sec * 1000 + itv.it_value.tv_usec / 1000; 
>  if (elapse == 0) 
>    return 0; 
>  if (!(timer_active = SetTimer (gethwnd(), 1, elapse, NULL))) 
>    {
>      __seterrno (); 
>      return -1; 
>    }
>
>elapse evaluates to 0 for values less than 1000 microseconds.  Thus, for
>small time values, the timer is simply killed.  Is it possible to changes
>this so that small time values are rounded up to the smallest resolution?

Your analysis of the problem is correct, IMO.  I'm going to check in the
following change to cygwin to work around this problem.

Thanks very much for tracking this down so precisely.

cgf

Index: window.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/window.cc,v
retrieving revision 1.4
diff -u -p -r1.4 window.cc
--- window.cc   2000/05/09 13:28:11     1.4
+++ window.cc   2000/06/26 22:31:00
@@ -176,7 +176,10 @@ setitimer (int which, const struct itime
   itv = *value;
   elapse = itv.it_value.tv_sec * 1000 + itv.it_value.tv_usec / 1000;
   if (elapse == 0)
-    return 0;
+    if (itv.it_value.tv_usec)
+      elapse = 1;
+    else
+      return 0;
   if (!(timer_active = SetTimer (gethwnd(), 1, elapse, NULL)))
     {
       __seterrno ();

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]