ev_timers.c (156953) | ev_timers.c (156956) |
---|---|
1/* 2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (c) 1995-1999 by Internet Software Consortium 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * --- 8 unchanged lines hidden (view full) --- 17 18/* ev_timers.c - implement timers for the eventlib 19 * vix 09sep95 [initial] 20 */ 21 22#if !defined(LINT) && !defined(CODECENTER) 23static const char rcsid[] = "$Id: ev_timers.c,v 1.2.2.1.4.5 2004/03/17 02:39:13 marka Exp $"; 24#endif | 1/* 2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (c) 1995-1999 by Internet Software Consortium 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * --- 8 unchanged lines hidden (view full) --- 17 18/* ev_timers.c - implement timers for the eventlib 19 * vix 09sep95 [initial] 20 */ 21 22#if !defined(LINT) && !defined(CODECENTER) 23static const char rcsid[] = "$Id: ev_timers.c,v 1.2.2.1.4.5 2004/03/17 02:39:13 marka Exp $"; 24#endif |
25#include <sys/cdefs.h> 26__FBSDID("$FreeBSD: head/lib/libc/isc/ev_timers.c 156956 2006-03-21 15:37:16Z ume $"); |
|
25 26/* Import. */ 27 28#include "port_before.h" | 27 28/* Import. */ 29 30#include "port_before.h" |
31#ifndef _LIBC |
|
29#include "fd_setsize.h" | 32#include "fd_setsize.h" |
33#endif |
|
30 31#include <errno.h> 32 | 34 35#include <errno.h> 36 |
37#ifndef _LIBC |
|
33#include <isc/assertions.h> | 38#include <isc/assertions.h> |
39#endif |
|
34#include <isc/eventlib.h> 35#include "eventlib_p.h" 36 37#include "port_after.h" 38 39/* Constants. */ 40 41#define MILLION 1000000 42#define BILLION 1000000000 43 44/* Forward. */ 45 | 40#include <isc/eventlib.h> 41#include "eventlib_p.h" 42 43#include "port_after.h" 44 45/* Constants. */ 46 47#define MILLION 1000000 48#define BILLION 1000000000 49 50/* Forward. */ 51 |
52#ifdef _LIBC 53static int __evOptMonoTime; 54#else |
|
46static int due_sooner(void *, void *); 47static void set_index(void *, int); 48static void free_timer(void *, void *); 49static void print_timer(void *, void *); 50static void idle_timeout(evContext, void *, struct timespec, struct timespec); 51 52/* Private type. */ 53 54typedef struct { 55 evTimerFunc func; 56 void * uap; 57 struct timespec lastTouched; 58 struct timespec max_idle; 59 evTimer * timer; 60} idle_timer; | 55static int due_sooner(void *, void *); 56static void set_index(void *, int); 57static void free_timer(void *, void *); 58static void print_timer(void *, void *); 59static void idle_timeout(evContext, void *, struct timespec, struct timespec); 60 61/* Private type. */ 62 63typedef struct { 64 evTimerFunc func; 65 void * uap; 66 struct timespec lastTouched; 67 struct timespec max_idle; 68 evTimer * timer; 69} idle_timer; |
70#endif |
|
61 62/* Public. */ 63 64struct timespec 65evConsTime(time_t sec, long nsec) { 66 struct timespec x; 67 68 x.tv_sec = sec; --- 64 unchanged lines hidden (view full) --- 133 if (clock_gettime(CLOCK_REALTIME, &tsnow) == 0) 134 return (tsnow); 135#endif 136 if (gettimeofday(&now, NULL) < 0) 137 return (evConsTime(0, 0)); 138 return (evTimeSpec(now)); 139} 140 | 71 72/* Public. */ 73 74struct timespec 75evConsTime(time_t sec, long nsec) { 76 struct timespec x; 77 78 x.tv_sec = sec; --- 64 unchanged lines hidden (view full) --- 143 if (clock_gettime(CLOCK_REALTIME, &tsnow) == 0) 144 return (tsnow); 145#endif 146 if (gettimeofday(&now, NULL) < 0) 147 return (evConsTime(0, 0)); 148 return (evTimeSpec(now)); 149} 150 |
151#ifndef _LIBC |
|
141struct timespec 142evLastEventTime(evContext opaqueCtx) { 143 evContext_p *ctx = opaqueCtx.opaque; 144 145 return (ctx->lastEventTime); 146} | 152struct timespec 153evLastEventTime(evContext opaqueCtx) { 154 evContext_p *ctx = opaqueCtx.opaque; 155 156 return (ctx->lastEventTime); 157} |
158#endif |
|
147 148struct timespec 149evTimeSpec(struct timeval tv) { 150 struct timespec ts; 151 152 ts.tv_sec = tv.tv_sec; 153 ts.tv_nsec = tv.tv_usec * 1000; 154 return (ts); 155} 156 | 159 160struct timespec 161evTimeSpec(struct timeval tv) { 162 struct timespec ts; 163 164 ts.tv_sec = tv.tv_sec; 165 ts.tv_nsec = tv.tv_usec * 1000; 166 return (ts); 167} 168 |
169#if !defined(USE_KQUEUE) || !defined(_LIBC) |
|
157struct timeval 158evTimeVal(struct timespec ts) { 159 struct timeval tv; 160 161 tv.tv_sec = ts.tv_sec; 162 tv.tv_usec = ts.tv_nsec / 1000; 163 return (tv); 164} | 170struct timeval 171evTimeVal(struct timespec ts) { 172 struct timeval tv; 173 174 tv.tv_sec = ts.tv_sec; 175 tv.tv_usec = ts.tv_nsec / 1000; 176 return (tv); 177} |
178#endif |
|
165 | 179 |
180#ifndef _LIBC |
|
166int 167evSetTimer(evContext opaqueCtx, 168 evTimerFunc func, 169 void *uap, 170 struct timespec due, 171 struct timespec inter, 172 evTimerID *opaqueID 173) { --- 316 unchanged lines hidden (view full) --- 490 */ 491 this->timer->inter = evConsTime(0, 0); 492 FREE(this); 493 } else { 494 /* evDrop() will reschedule the timer. */ 495 this->timer->inter = evSubTime(this->max_idle, idle); 496 } 497} | 181int 182evSetTimer(evContext opaqueCtx, 183 evTimerFunc func, 184 void *uap, 185 struct timespec due, 186 struct timespec inter, 187 evTimerID *opaqueID 188) { --- 316 unchanged lines hidden (view full) --- 505 */ 506 this->timer->inter = evConsTime(0, 0); 507 FREE(this); 508 } else { 509 /* evDrop() will reschedule the timer. */ 510 this->timer->inter = evSubTime(this->max_idle, idle); 511 } 512} |
513#endif |
|