VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/darwin/time-r0drv-darwin.cpp@ 2555

Last change on this file since 2555 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1/* $Id: time-r0drv-darwin.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - Time, Ring-0 Driver, Darwin.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP RTLOGGROUP_TIME
27#include "the-darwin-kernel.h"
28#include <iprt/time.h>
29#include <iprt/asm.h>
30
31
32DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)
33{
34 static int8_t s_fSimple = -1;
35
36 /* first call: check if life is simple or not. */
37 if (s_fSimple < 0)
38 {
39 struct mach_timebase_info Info;
40 clock_timebase_info(&Info);
41 ASMAtomicXchgS8((int8_t * volatile)&s_fSimple, Info.denom == 1 && Info.numer == 1);
42 }
43
44 /* special case: absolute time is in nanoseconds */
45 if (s_fSimple)
46 return mach_absolute_time();
47
48 /* general case: let mach do the mult/div for us. */
49 uint64_t u64;
50 absolutetime_to_nanoseconds(mach_absolute_time(), &u64);
51 return u64;
52}
53
54
55/**
56 * Gets the current nanosecond timestamp.
57 *
58 * @returns nanosecond timestamp.
59 */
60RTDECL(uint64_t) RTTimeNanoTS(void)
61{
62 return rtTimeGetSystemNanoTS();
63}
64
65
66/**
67 * Gets the current millisecond timestamp.
68 *
69 * @returns millisecond timestamp.
70 */
71RTDECL(uint64_t) RTTimeMilliTS(void)
72{
73 return rtTimeGetSystemNanoTS() / 1000000;
74}
75
76
77/**
78 * Gets the current nanosecond timestamp.
79 *
80 * This differs from RTTimeNanoTS in that it will use system APIs and not do any
81 * resolution or performance optimizations.
82 *
83 * @returns nanosecond timestamp.
84 */
85RTDECL(uint64_t) RTTimeSystemNanoTS(void)
86{
87 return rtTimeGetSystemNanoTS();
88}
89
90
91/**
92 * Gets the current millisecond timestamp.
93 *
94 * This differs from RTTimeNanoTS in that it will use system APIs and not do any
95 * resolution or performance optimizations.
96 *
97 * @returns millisecond timestamp.
98 */
99RTDECL(uint64_t) RTTimeSystemMilliTS(void)
100{
101 return rtTimeGetSystemNanoTS() / 1000000;
102}
103
104
105/**
106 * Gets the current system time.
107 *
108 * @returns pTime.
109 * @param pTime Where to store the time.
110 */
111RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
112{
113 uint32_t u32Secs;
114 uint32_t u32Nanosecs;
115 clock_get_calendar_nanotime(&u32Secs, &u32Nanosecs);
116 return RTTimeSpecSetNano(pTime, (uint64_t)u32Secs * 1000000000 + u32Nanosecs);
117}
118
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette