/[gxemul]/trunk/src/timer.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/timer.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 41 by dpavlin, Mon Oct 8 16:21:17 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: timer.c,v 1.6 2006/12/30 13:30:53 debug Exp $   *  $Id: timer.c,v 1.9 2007/06/15 17:02:38 debug Exp $
29   *   *
30   *  Timer framework. This is used by emulated clocks.   *  Timer framework. This is used by emulated clocks.
31   */   */
# Line 37  Line 37 
37  #include <unistd.h>  #include <unistd.h>
38  #include <sys/time.h>  #include <sys/time.h>
39    
40    #include "misc.h"
41  #include "timer.h"  #include "timer.h"
42    
43    
# Line 63  static double timer_current_time_step; Line 64  static double timer_current_time_step;
64    
65  static int timer_is_running;  static int timer_is_running;
66    
67  #define SECONDS_BETWEEN_GETTIMEOFDAY_SYNCH      1.5  #define SECONDS_BETWEEN_GETTIMEOFDAY_SYNCH      1.65
68    
69    
70  /*  /*
# Line 76  static int timer_is_running; Line 77  static int timer_is_running;
77  struct timer *timer_add(double freq, void (*timer_tick)(struct timer *timer,  struct timer *timer_add(double freq, void (*timer_tick)(struct timer *timer,
78          void *extra), void *extra)          void *extra), void *extra)
79  {  {
80          struct timer *newtimer = malloc(sizeof(struct timer));          struct timer *newtimer;
81          if (newtimer == NULL) {  
82                  fprintf(stderr, "out of memory\n");          CHECK_ALLOCATION(newtimer = malloc(sizeof(struct timer)));
                 exit(1);  
         }  
83    
84          if (freq <= 0.00000001)          if (freq <= 0.00000001)
85                  freq = 0.00000001;                  freq = 0.00000001;
# Line 168  static void timer_tick(int signal_nr) Line 167  static void timer_tick(int signal_nr)
167                          tv.tv_sec --;                          tv.tv_sec --;
168                  }                  }
169    
170  #if 0  #ifdef TIMER_DEBUG
171                  /*  For debugging/testing:  */                  /*  For debugging/testing:  */
172                  {                  {
173                          double diff = tv.tv_usec * 0.000001 + tv.tv_sec                          double diff = tv.tv_usec * 0.000001 + tv.tv_sec
# Line 285  void timer_init(void) Line 284  void timer_init(void)
284          timer_is_running = 0;          timer_is_running = 0;
285          timer_countdown_to_next_gettimeofday = 0;          timer_countdown_to_next_gettimeofday = 0;
286    
287          timer_freq = 50.0;          timer_freq = TIMER_BASE_FREQUENCY;
288          timer_current_time_step = 1.0 / timer_freq;          timer_current_time_step = 1.0 / timer_freq;
289    
290  #ifdef TEST  #ifdef TEST

Legend:
Removed from v.41  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26