www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/12/08/21:11:24

Date: Mon, 8 Dec 1997 18:10:16 -0800 (PST)
Message-Id: <199712090210.SAA12010@adit.ap.net>
Mime-Version: 1.0
To: massimin AT clipper DOT ens DOT fr (Pascal Massimino)
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: itimers
Cc: djgpp AT delorie DOT com, djgpp-workers AT delorie DOT com

At 06:36  12/7/1997 +0100, Pascal Massimino wrote in private mail:
>
>	Hi M. Eldredge,
>
>
>> DJGPP does provide `getitimer' and `setitimer'. Start by reading their docs
>> with the rest of those for libc, and make sure what you're doing matches. If
>> that does not provide enlightenment, please post a short, but complete,
>> example that reproduces the problem. Tell what you think it should do and
>> what it does. (You don't say what you mean by "it refuses to work".) Also
>> post the information requested by FAQ section 6.12.
>
>
>	what I mean by 'refuses to work' is that the following proggy:
>
>-Start-----------------------------------------------------------------
>
>#include <sys/time.h>
>void main( )
>{
>   struct itimerval Val;
>
>   Val.it_value.tv_sec = 5;
>   Val.it_value.tv_usec = 0;
>   Val.it_interval.tv_sec = 5;
>   Val.it_interval.tv_usec = 0;
>   setitimer( ITIMER_REAL, &Val, NULL );
>
>   while(1)
>   {
>       getitimer( ITIMER_REAL, &Val );
>       printf( "%ld ", Val.it_value.tv_sec );
>       printf( "%ld ", Val.it_value.tv_usec );
>       printf( "%ld ", Val.it_interval.tv_sec );
>       printf( "%ld \r", Val.it_interval.tv_usec );
>   }
>}
>
>-End-------------------------------------------------------------------
>
>	won't show any changement in Val.it_value. It remains
>	sticked to 0. However, SIGALRM is delivered right
>	after 5 second.
>
>	My goal is just to monitor time decrementation
>	within these 5 seconds, and not to take any 
>	sigaction() upon completion.
>	Am I doing right?
Thanks for the complete report. It turns out that `getitimer' had not been
completely implemented and just returned zeros. I have included a patch
which fixes it, although not necessarily in the best way. I have also CC'ed
a copy to the maintainers so hopefully this will be fixed in the next release.

--cut--
*** src/libc/posix/signal/itimer.bak	Sat Jul 15 14:30:10 1995
--- src/libc/posix/signal/itimer.c	Mon Dec  8 17:39:00 1997
***************
*** 9,36 ****
  #include <dpmi.h>
  #include <signal.h>
  
! static struct itimerval real, prof;
! 
! /* not right, should compute from current tic count.  Do later */
! int getitimer(int which, struct itimerval *value)
! {
!   if(which == ITIMER_REAL) {
!     *value = real;
!     return 0;
!   } else if(which == ITIMER_PROF) {
!     *value = prof;
!     return 0;
!   }
!   errno = EINVAL;
!   return -1;
! }
! 
! extern unsigned __djgpp_timer_countdown;
  extern __dpmi_paddr __djgpp_old_timer;
  extern int __djgpp_timer_hdlr;
  static char timer_on = 0;
  static int sigtype = SIGALRM;
  static int reload = 0;
  
  static void stop_timer(void)
  {
--- 9,44 ----
  #include <dpmi.h>
  #include <signal.h>
  
! extern volatile unsigned __djgpp_timer_countdown;
  extern __dpmi_paddr __djgpp_old_timer;
  extern int __djgpp_timer_hdlr;
  static char timer_on = 0;
  static int sigtype = SIGALRM;
  static int reload = 0;
+ 
+ int getitimer(int which, struct itimerval *value)
+ {
+   int secs;
+   /* FIXME: What should happen if the timer isn't running? */
+   if (!timer_on)
+     {
+       errno = EINVAL;
+       return -1;
+     }
+   if ((which != ITIMER_REAL) && (which != ITIMER_PROF))
+     {
+       errno = EINVAL;
+       return -1;
+     }
+   /* I'll use floating point, because I'm lazy */
+   /* FIXME: Is it really 18.2 ticks per second, or is that an
approximation? */
+   secs = __djgpp_timer_countdown / 18.2;
+   value->it_value.tv_sec = secs;
+   value->it_value.tv_usec = ((__djgpp_timer_countdown / 18.2) 
+ 			     - (double)secs) * 1000;
+   return 0;
+ }
+ 
  
  static void stop_timer(void)
  {

--cut--

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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