VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1/* $Id: time-r0drv-darwin.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT - Time, Ring-0 Driver, Darwin.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
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
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#define LOG_GROUP RTLOGGROUP_TIME
32#include "the-darwin-kernel.h"
33#include "internal/iprt.h"
34#include <iprt/time.h>
35
36#include <iprt/asm.h>
37
38
39DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)
40{
41 static int8_t s_fSimple = -1;
42
43 /* first call: check if life is simple or not. */
44 if (s_fSimple < 0)
45 {
46 struct mach_timebase_info Info;
47 clock_timebase_info(&Info);
48 ASMAtomicXchgS8((int8_t * volatile)&s_fSimple, Info.denom == 1 && Info.numer == 1);
49 }
50
51 /* special case: absolute time is in nanoseconds */
52 if (s_fSimple)
53 return mach_absolute_time();
54
55 /* general case: let mach do the mult/div for us. */
56 uint64_t u64;
57 absolutetime_to_nanoseconds(mach_absolute_time(), &u64);
58 return u64;
59}
60
61
62RTDECL(uint64_t) RTTimeNanoTS(void)
63{
64 return rtTimeGetSystemNanoTS();
65}
66
67
68RTDECL(uint64_t) RTTimeMilliTS(void)
69{
70 return rtTimeGetSystemNanoTS() / 1000000;
71}
72
73
74RTDECL(uint64_t) RTTimeSystemNanoTS(void)
75{
76 return rtTimeGetSystemNanoTS();
77}
78
79
80RTDECL(uint64_t) RTTimeSystemMilliTS(void)
81{
82 return rtTimeGetSystemNanoTS() / 1000000;
83}
84
85
86RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
87{
88#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
89 uint32_t uSecs;
90 uint32_t uNanosecs;
91#else
92 clock_sec_t uSecs;
93 clock_nsec_t uNanosecs;
94#endif
95 clock_get_calendar_nanotime(&uSecs, &uNanosecs);
96 return RTTimeSpecSetNano(pTime, (uint64_t)uSecs * 1000000000 + uNanosecs);
97}
98
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