Annotation of embedaddon/bird/sysdep/unix/timer.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  *     BIRD -- Unix Timers
                      3:  *
                      4:  *     (c) 1998 Martin Mares <mj@ucw.cz>
                      5:  *
                      6:  *     Can be freely distributed and used under the terms of the GNU GPL.
                      7:  */
                      8: 
                      9: #ifndef _BIRD_TIMER_H_
                     10: #define _BIRD_TIMER_H_
                     11: 
                     12: #include <time.h>
                     13: 
                     14: #include "lib/resource.h"
                     15: 
                     16: typedef time_t bird_clock_t;           /* Use instead of time_t */
                     17: 
                     18: typedef struct timer {
                     19:   resource r;
                     20:   void (*hook)(struct timer *);
                     21:   void *data;
                     22:   unsigned randomize;                  /* Amount of randomization */
                     23:   unsigned recurrent;                  /* Timer recurrence */
                     24:   node n;                              /* Internal link */
                     25:   bird_clock_t expires;                        /* 0=inactive */
                     26: } timer;
                     27: 
                     28: timer *tm_new(pool *);
                     29: void tm_start(timer *, unsigned after);
                     30: void tm_stop(timer *);
                     31: void tm_dump_all(void);
                     32: 
                     33: extern bird_clock_t now;               /* Relative, monotonic time in seconds */
                     34: extern bird_clock_t now_real;          /* Time in seconds since fixed known epoch */
                     35: extern bird_clock_t boot_time;
                     36: 
                     37: static inline int
                     38: tm_active(timer *t)
                     39: {
                     40:   return t->expires != 0;
                     41: }
                     42: 
                     43: static inline bird_clock_t
                     44: tm_remains(timer *t)
                     45: {
                     46:   return t->expires ? t->expires - now : 0;
                     47: }
                     48: 
                     49: static inline void
                     50: tm_start_max(timer *t, unsigned after)
                     51: {
                     52:   bird_clock_t rem = tm_remains(t);
                     53:   tm_start(t, (rem > after) ? rem : after);
                     54: }
                     55: 
                     56: static inline timer *
                     57: tm_new_set(pool *p, void (*hook)(struct timer *), void *data, unsigned rand, unsigned rec)
                     58: {
                     59:   timer *t = tm_new(p);
                     60:   t->hook = hook;
                     61:   t->data = data;
                     62:   t->randomize = rand;
                     63:   t->recurrent = rec;
                     64:   return t;
                     65: }
                     66: 
                     67: 
                     68: struct timeformat {
                     69:   char *fmt1, *fmt2;
                     70:   bird_clock_t limit;
                     71: };
                     72: 
                     73: bird_clock_t tm_parse_date(char *);    /* Convert date to bird_clock_t */
                     74: bird_clock_t tm_parse_datetime(char *);        /* Convert date to bird_clock_t */
                     75: 
                     76: #define TM_DATETIME_BUFFER_SIZE 32     /* Buffer size required by tm_format_datetime */
                     77: void
                     78: tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t);
                     79: 
                     80: #ifdef TIME_T_IS_64BIT
                     81: #define TIME_INFINITY 0x7fffffffffffffff
                     82: #else
                     83: #ifdef TIME_T_IS_SIGNED
                     84: #define TIME_INFINITY 0x7fffffff
                     85: #else
                     86: #define TIME_INFINITY 0xffffffff
                     87: #endif
                     88: #endif
                     89: 
                     90: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>