/* $Id: fpm_clock.c,v 1.4 2008/09/18 23:19:59 anight Exp $ */ /* (c) 2007,2008 Andrei Nigmatulin */ #include "fpm_config.h" #if defined(HAVE_CLOCK_GETTIME) #include <time.h> /* for CLOCK_MONOTONIC */ #endif #include "fpm_clock.h" #include "zlog.h" /* posix monotonic clock - preferred source of time */ #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) static int monotonic_works; int fpm_clock_init() /* {{{ */ { struct timespec ts; monotonic_works = 0; if (0 == clock_gettime(CLOCK_MONOTONIC, &ts)) { monotonic_works = 1; } return 0; } /* }}} */ int fpm_clock_get(struct timeval *tv) /* {{{ */ { if (monotonic_works) { struct timespec ts; if (0 > clock_gettime(CLOCK_MONOTONIC, &ts)) { zlog(ZLOG_SYSERROR, "clock_gettime() failed"); return -1; } tv->tv_sec = ts.tv_sec; tv->tv_usec = ts.tv_nsec / 1000; return 0; } return gettimeofday(tv, 0); } /* }}} */ /* macosx clock */ #elif defined(HAVE_CLOCK_GET_TIME) #include <mach/mach.h> #include <mach/clock.h> #include <mach/mach_error.h> static clock_serv_t mach_clock; /* this code borrowed from here: http://lists.apple.com/archives/Darwin-development/2002/Mar/msg00746.html */ /* mach_clock also should be re-initialized in child process after fork */ int fpm_clock_init() /* {{{ */ { kern_return_t ret; mach_timespec_t aTime; ret = host_get_clock_service(mach_host_self(), REALTIME_CLOCK, &mach_clock); if (ret != KERN_SUCCESS) { zlog(ZLOG_ERROR, "host_get_clock_service() failed: %s", mach_error_string(ret)); return -1; } /* test if it works */ ret = clock_get_time(mach_clock, &aTime); if (ret != KERN_SUCCESS) { zlog(ZLOG_ERROR, "clock_get_time() failed: %s", mach_error_string(ret)); return -1; } return 0; } /* }}} */ int fpm_clock_get(struct timeval *tv) /* {{{ */ { kern_return_t ret; mach_timespec_t aTime; ret = clock_get_time(mach_clock, &aTime); if (ret != KERN_SUCCESS) { zlog(ZLOG_ERROR, "clock_get_time() failed: %s", mach_error_string(ret)); return -1; } tv->tv_sec = aTime.tv_sec; tv->tv_usec = aTime.tv_nsec / 1000; return 0; } /* }}} */ #else /* no clock */ int fpm_clock_init() /* {{{ */ { return 0; } /* }}} */ int fpm_clock_get(struct timeval *tv) /* {{{ */ { return gettimeofday(tv, 0); } /* }}} */ #endif
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
events | Folder | 0755 |
|
|
fastcgi.c | File | 25.94 KB | 0644 |
|
fastcgi.h | File | 4.47 KB | 0644 |
|
fpm.c | File | 2.84 KB | 0644 |
|
fpm.h | File | 1.13 KB | 0644 |
|
fpm_arrays.h | File | 1.82 KB | 0644 |
|
fpm_atomic.h | File | 3.95 KB | 0644 |
|
fpm_children.c | File | 10.99 KB | 0644 |
|
fpm_children.h | File | 873 B | 0644 |
|
fpm_cleanup.c | File | 849 B | 0644 |
|
fpm_cleanup.h | File | 519 B | 0644 |
|
fpm_clock.c | File | 2.23 KB | 0644 |
|
fpm_clock.h | File | 239 B | 0644 |
|
fpm_conf.c | File | 49.14 KB | 0644 |
|
fpm_conf.h | File | 2.43 KB | 0644 |
|
fpm_env.c | File | 5.39 KB | 0644 |
|
fpm_env.h | File | 491 B | 0644 |
|
fpm_events.c | File | 11.67 KB | 0644 |
|
fpm_events.h | File | 1.59 KB | 0644 |
|
fpm_log.c | File | 11.53 KB | 0644 |
|
fpm_log.h | File | 300 B | 0644 |
|
fpm_main.c | File | 62.74 KB | 0644 |
|
fpm_php.c | File | 6.42 KB | 0644 |
|
fpm_php.h | File | 1.23 KB | 0644 |
|
fpm_php_trace.c | File | 3.49 KB | 0644 |
|
fpm_process_ctl.c | File | 13.65 KB | 0644 |
|
fpm_process_ctl.h | File | 1.23 KB | 0644 |
|
fpm_request.c | File | 8.01 KB | 0644 |
|
fpm_request.h | File | 1.18 KB | 0644 |
|
fpm_scoreboard.c | File | 7.84 KB | 0644 |
|
fpm_scoreboard.h | File | 2.5 KB | 0644 |
|
fpm_shm.c | File | 1.23 KB | 0644 |
|
fpm_shm.h | File | 263 B | 0644 |
|
fpm_signals.c | File | 4.72 KB | 0644 |
|
fpm_signals.h | File | 315 B | 0644 |
|
fpm_sockets.c | File | 11.39 KB | 0644 |
|
fpm_sockets.h | File | 1006 B | 0644 |
|
fpm_status.c | File | 13.7 KB | 0644 |
|
fpm_status.h | File | 1.03 KB | 0644 |
|
fpm_stdio.c | File | 7.36 KB | 0644 |
|
fpm_stdio.h | File | 569 B | 0644 |
|
fpm_str.h | File | 483 B | 0644 |
|
fpm_systemd.c | File | 3.11 KB | 0644 |
|
fpm_systemd.h | File | 275 B | 0644 |
|
fpm_trace.c | File | 641 B | 0644 |
|
fpm_trace.h | File | 378 B | 0644 |
|
fpm_trace_ptrace.c | File | 1.6 KB | 0644 |
|
fpm_unix.c | File | 19.23 KB | 0644 |
|
fpm_unix.h | File | 518 B | 0644 |
|
fpm_worker_pool.c | File | 1.57 KB | 0644 |
|
fpm_worker_pool.h | File | 1.23 KB | 0644 |
|
zlog.c | File | 4.47 KB | 0644 |
|
zlog.h | File | 978 B | 0644 |
|