Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmlibuv/src/unix/posix-hrtime.c
3156 views
1
/* Copyright libuv project contributors. All rights reserved.
2
*
3
* Permission is hereby granted, free of charge, to any person obtaining a copy
4
* of this software and associated documentation files (the "Software"), to
5
* deal in the Software without restriction, including without limitation the
6
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
* sell copies of the Software, and to permit persons to whom the Software is
8
* furnished to do so, subject to the following conditions:
9
*
10
* The above copyright notice and this permission notice shall be included in
11
* all copies or substantial portions of the Software.
12
*
13
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
* IN THE SOFTWARE.
20
*/
21
22
#include "uv.h"
23
#include "internal.h"
24
25
#if defined(__APPLE__)
26
/* Special case for CMake bootstrap: no clock_gettime on macOS < 10.12 */
27
28
#ifndef CMAKE_BOOTSTRAP
29
#error "This code path meant only for use during CMake bootstrap."
30
#endif
31
32
#include <mach/mach.h>
33
#include <mach/mach_time.h>
34
35
uint64_t uv__hrtime(uv_clocktype_t type) {
36
static mach_timebase_info_data_t info;
37
38
if ((ACCESS_ONCE(uint32_t, info.numer) == 0 ||
39
ACCESS_ONCE(uint32_t, info.denom) == 0) &&
40
mach_timebase_info(&info) != KERN_SUCCESS)
41
abort();
42
43
return mach_absolute_time() * info.numer / info.denom;
44
}
45
46
#elif defined(__hpux)
47
/* Special case for CMake bootstrap: no CLOCK_MONOTONIC on HP-UX */
48
49
#ifndef CMAKE_BOOTSTRAP
50
#error "This code path meant only for use during CMake bootstrap."
51
#endif
52
53
#include <stdint.h>
54
#include <time.h>
55
56
uint64_t uv__hrtime(uv_clocktype_t type) {
57
return (uint64_t) gethrtime();
58
}
59
60
#else
61
62
#include <stdint.h>
63
#include <time.h>
64
65
#undef NANOSEC
66
#define NANOSEC ((uint64_t) 1e9)
67
68
uint64_t uv__hrtime(uv_clocktype_t type) {
69
struct timespec ts;
70
clock_gettime(CLOCK_MONOTONIC, &ts);
71
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
72
}
73
74
#endif
75
76