VirtualBox

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

Last change on this file since 22052 was 22052, checked in by vboxsync, 15 years ago

IPRT: RT_MORE_STRICT for r0rdv and r0drv/darwin.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1/* $Id: time-r0drv-darwin.cpp 22052 2009-08-07 09:45:48Z vboxsync $ */
2/** @file
3 * IPRT - Time, Ring-0 Driver, Darwin.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#define LOG_GROUP RTLOGGROUP_TIME
36#include "the-darwin-kernel.h"
37#include "internal/iprt.h"
38#include <iprt/time.h>
39
40#include <iprt/asm.h>
41
42
43DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)
44{
45 static int8_t s_fSimple = -1;
46
47 /* first call: check if life is simple or not. */
48 if (s_fSimple < 0)
49 {
50 struct mach_timebase_info Info;
51 clock_timebase_info(&Info);
52 ASMAtomicXchgS8((int8_t * volatile)&s_fSimple, Info.denom == 1 && Info.numer == 1);
53 }
54
55 /* special case: absolute time is in nanoseconds */
56 if (s_fSimple)
57 return mach_absolute_time();
58
59 /* general case: let mach do the mult/div for us. */
60 uint64_t u64;
61 absolutetime_to_nanoseconds(mach_absolute_time(), &u64);
62 return u64;
63}
64
65
66RTDECL(uint64_t) RTTimeNanoTS(void)
67{
68 return rtTimeGetSystemNanoTS();
69}
70
71
72RTDECL(uint64_t) RTTimeMilliTS(void)
73{
74 return rtTimeGetSystemNanoTS() / 1000000;
75}
76
77
78RTDECL(uint64_t) RTTimeSystemNanoTS(void)
79{
80 return rtTimeGetSystemNanoTS();
81}
82
83
84RTDECL(uint64_t) RTTimeSystemMilliTS(void)
85{
86 return rtTimeGetSystemNanoTS() / 1000000;
87}
88
89
90RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
91{
92#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
93 uint32_t uSecs;
94 uint32_t uNanosecs;
95#else
96 clock_sec_t uSecs;
97 clock_nsec_t uNanosecs;
98#endif
99 clock_get_calendar_nanotime(&uSecs, &uNanosecs);
100 return RTTimeSpecSetNano(pTime, (uint64_t)uSecs * 1000000000 + uNanosecs);
101}
102
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