Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

timer.hh

Go to the documentation of this file.
00001 
00002 #ifndef TIMER_HH
00003 #define TIMER_HH
00004 #include "rcs_defs.hh"          /* RCS_EXPORT */
00005 
00006 
00007 extern "C"
00008 {
00009 #ifndef NO_STDIO
00010 #include <stdio.h>              /* NULL */
00011 #endif
00012 }
00013 
00014 #ifdef MSDOS
00015 #ifdef USE_SEMS_FOR_TIMER
00016 #undef USE_SEMS_FOR_TIMER
00017 #endif
00018 #endif
00019 
00020 #if USE_SEMS_FOR_TIMER
00021 #include "sem.hh"               // RCS_SEMAPHORE
00022 #endif
00023 
00024 /* Too many files expect etime() and esleep() to be here to change now. */
00025 #include "_timer.h"             /* etime(), esleep() */
00026 
00027 /* prototype for user-defined timing function */
00028 #ifndef sparcworks
00029 typedef int (*RCS_TIMERFUNC) (void *_arg = NULL);
00030 #else
00031 typedef int (*RCS_TIMERFUNC) (void *_arg);
00032 #endif
00033 
00034 /* prototype for signal hander function */
00035 typedef void (*RCS_SIGFUNC) (...);
00036 
00037 #if (defined (SUN) || defined (LYNX)) && !defined(lynxosVME) && !defined(sunos4CC)
00038 
00039 /* set up SIGALRM to go off after time, either once or periodically */
00040 extern int itimer_set (double time, int periodic = 1);
00041 
00042 /* attach a function to the SIGALRM handler */
00043 extern void itimer_attach (RCS_SIGFUNC function);
00044 
00045 /* block on arrival of SIGALRM */
00046 extern void itimer_wait ();
00047 
00048 #endif /* SUN or LYNX */
00049 
00050 /*
00051   general-purpose timer, which can be used for waiting until a
00052   synchronous time tick, slept on for any period at all, or to
00053   obtain a time in system clock ticks from creation of the timer.
00054   */
00055 class RCS_EXPORT RCS_TIMER
00056 {
00057 public:
00058   RCS_TIMER (double timeout, RCS_TIMERFUNC function =
00059              (RCS_TIMERFUNC) NULL, void *arg = NULL);
00060     RCS_TIMER (char *process_name, char *timer_config_file);
00061     RCS_TIMER (double _timeout, char *process_name, char *timer_config_file);
00062   /* timeout is wait interval, rounded up to clock tick resolution;
00063      function is external time base, if provided */
00064    ~RCS_TIMER ();
00065   int wait ();                  /* wait on synch; returns # of cycles missed */
00066   double load ();               /* returns % loading on timer, 0.0 means
00067                                    all waits, 1.0 means no time in wait */
00068   void sync ();                 /* restart the wait interval. */
00069   double timeout;               /* copy of timeout */
00070 
00071 private:
00072   void init (double _timeout, int _id);
00073 
00074   void zero_timer ();
00075   void set_timeout (double _timeout);
00076 #if 0
00077   void read_config_file (char *process, char *config_file);
00078 #endif
00079   RCS_TIMERFUNC function;       /* copy of function */
00080   void *arg;                    /* arg for function */
00081   double last_time;             /* last wakeup, in ticks from epoch */
00082   double start_time;            /* epoch time at creation of timer */
00083   double idle;                  /* accumulated idle time */
00084   int counts;                   /* accumulated waits */
00085   int counts_since_real_sleep;
00086   int counts_per_real_sleep;
00087   double time_since_real_sleep;
00088 #ifdef USE_SEMS_FOR_TIMER
00089   RCS_SEMAPHORE **sems;
00090 #endif
00091   int num_sems;
00092   int sem_key;
00093   int id;
00094   int create_sems;
00095   int poller_pid;
00096   double clk_tck_val;
00097 };
00098 
00099 #endif

Generated on Sun Dec 2 15:56:53 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001