VirtualBox

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

Last change on this file since 21280 was 16332, checked in by vboxsync, 16 years ago

time-r0drv-darwin.cpp: removed duplicated documentation.

  • 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 16332 2009-01-28 20:27:46Z 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 <iprt/time.h>
38#include <iprt/asm.h>
39
40
41DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)
42{
43 static int8_t s_fSimple = -1;
44
45 /* first call: check if life is simple or not. */
46 if (s_fSimple < 0)
47 {
48 struct mach_timebase_info Info;
49 clock_timebase_info(&Info);
50 ASMAtomicXchgS8((int8_t * volatile)&s_fSimple, Info.denom == 1 && Info.numer == 1);
51 }
52
53 /* special case: absolute time is in nanoseconds */
54 if (s_fSimple)
55 return mach_absolute_time();
56
57 /* general case: let mach do the mult/div for us. */
58 uint64_t u64;
59 absolutetime_to_nanoseconds(mach_absolute_time(), &u64);
60 return u64;
61}
62
63
64RTDECL(uint64_t) RTTimeNanoTS(void)
65{
66 return rtTimeGetSystemNanoTS();
67}
68
69
70RTDECL(uint64_t) RTTimeMilliTS(void)
71{
72 return rtTimeGetSystemNanoTS() / 1000000;
73}
74
75
76RTDECL(uint64_t) RTTimeSystemNanoTS(void)
77{
78 return rtTimeGetSystemNanoTS();
79}
80
81
82RTDECL(uint64_t) RTTimeSystemMilliTS(void)
83{
84 return rtTimeGetSystemNanoTS() / 1000000;
85}
86
87
88RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
89{
90#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
91 uint32_t uSecs;
92 uint32_t uNanosecs;
93#else
94 clock_sec_t uSecs;
95 clock_nsec_t uNanosecs;
96#endif
97 clock_get_calendar_nanotime(&uSecs, &uNanosecs);
98 return RTTimeSpecSetNano(pTime, (uint64_t)uSecs * 1000000000 + uNanosecs);
99}
100
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