xref: /php-src/Zend/zend_hrtime.c (revision 6c4e3c0f)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Author: Niklas Keller <kelunik@php.net>                              |
14    | Author: Anatol Belski <ab@php.net>                                   |
15    +----------------------------------------------------------------------+
16  */
17 
18 #include "zend.h"
19 #include "zend_hrtime.h"
20 
21 /* This file reuses code parts from the cross-platform timer library
22 	Public Domain - 2011 Mattias Jansson / Rampant Pixels */
23 
24 #if ZEND_HRTIME_PLATFORM_POSIX
25 
26 # include <unistd.h>
27 # include <time.h>
28 # include <string.h>
29 
30 #elif ZEND_HRTIME_PLATFORM_WINDOWS
31 
32 # define WIN32_LEAN_AND_MEAN
33 
34 ZEND_API double zend_hrtime_timer_scale = .0;
35 
36 #elif ZEND_HRTIME_PLATFORM_APPLE
37 
38 # include <mach/mach_time.h>
39 # include <string.h>
40 ZEND_API mach_timebase_info_data_t zend_hrtime_timerlib_info = {
41 	.numer = 0,
42 	.denom = 1,
43 };
44 
45 #elif ZEND_HRTIME_PLATFORM_HPUX
46 
47 # include <sys/time.h>
48 
49 #elif ZEND_HRTIME_PLATFORM_AIX
50 
51 # include <sys/time.h>
52 # include <sys/systemcfg.h>
53 
54 #endif
55 
zend_startup_hrtime(void)56 void zend_startup_hrtime(void)
57 {
58 #if ZEND_HRTIME_PLATFORM_WINDOWS
59 
60 	LARGE_INTEGER tf = {0};
61 	if (QueryPerformanceFrequency(&tf) || 0 != tf.QuadPart) {
62 		zend_hrtime_timer_scale = (double)ZEND_NANO_IN_SEC / (zend_hrtime_t)tf.QuadPart;
63 	}
64 
65 #elif ZEND_HRTIME_PLATFORM_APPLE
66 
67 	mach_timebase_info(&zend_hrtime_timerlib_info);
68 
69 #endif
70 }
71