www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000272

When Created: 02/10/1999 04:00:12
Against DJGPP version: 2.02
By whom: vvs@auto.bnm.org
Abstract: getitimer bug
getitimer sometimes return incorrect values

Solution added: 02/10/1999 04:00:51
By whom: vvs@auto.bnm.org
Apply the following patch:

--- itimer.ori	Thu Jan  1 22:57:00 1998
+++ itimer.c	Wed Feb 10 11:02:16 1999
@@ -5,8 +5,8 @@
 
    Changed to work with SIGALRM & SIGPROF by Tom Demmer.
    Gotchas:
-     - It relies on uclock(), which does not work under Windows 95.
-     - It screws up debuggers for reasons I cannot figure out.
+     - It relies on uclock(), which does not work as expected under Windows 9x.
+     - It screws up some debuggers (see DJGPP FAQ list 2.11, question 12.10).
      - Both is true for the old version, too.
 */
 
@@ -16,6 +16,7 @@
 #include <dpmi.h>
 #include <signal.h>
 #include <go32.h>
+#include <dos.h>
 
 static uclock_t r_exp, r_rel,  /* When REAL expires & reload value */
                 p_exp, p_rel;  /* When PROF expires & reload value */
@@ -26,8 +27,15 @@
 getitimer(int which, struct itimerval *value)
 {
   uclock_t rel;
+  int save_istate;
 
+  /* This is superfluous  */
   u_now = uclock();
+
+  /* Potential race condition here with timer_action.
+     This critical section must run with interrupts disabled  */
+  save_istate = disable();
+
   if (which == ITIMER_REAL)
   {
     if (r_exp)
@@ -36,7 +44,7 @@
       rel   = r_rel;
     }
     else
-      r_exp =  rel = 0;
+      u_now =  rel = 0;
   }
   else if (which == ITIMER_PROF)
   {
@@ -53,6 +61,10 @@
     errno = EINVAL;
     return -1;
   }
+
+  if (save_istate)
+    enable();
+
   value->it_value.tv_sec = u_now / UCLOCKS_PER_SEC;
   value->it_value.tv_usec= (u_now - value->it_value.tv_sec*3433)/4096;
   value->it_interval.tv_sec = rel / UCLOCKS_PER_SEC;
@@ -65,7 +77,7 @@
 extern int __djgpp_timer_hdlr;
 static char timer_on = 0;
 
-/* Set back IRQ2 handler to default values and disable own signal
+/* Set back IRQ0 handler to default values and disable own signal
    handler */
 static void
 stop_timer(void)

Fixed in version on 02/10/1999 04:00:27
By whom: vvs@auto.bnm.org



  webmaster     delorie software   privacy  
  Copyright © 2010   by DJ Delorie     Updated Jul 2010