time-darwin.cpp revision c58f1213e628a545081c70e26c6b67a841cff880
/* $Id$ */
/** @file
* IPRT - Time, Darwin.
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_TIME
#define RTTIME_INCL_TIMEVAL
#include <mach/mach_time.h>
#include <mach/kern_return.h>
#include <time.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static struct mach_timebase_info g_Info = { 0, 0 };
static double g_rdFactor = 0.0;
static bool g_fFailedToGetTimeBaseInfo = false;
/**
* Perform lazy init (pray we're not racing anyone in a bad way).
*/
static void rtTimeDarwinLazyInit(void)
{
struct mach_timebase_info Info;
{
}
else
{
g_fFailedToGetTimeBaseInfo = true;
}
}
/**
* Internal worker.
* @returns Nanosecond timestamp.
*/
{
/* Lazy init. */
/* special case: absolute time is in nanoseconds */
return mach_absolute_time();
/* general case: multiply by factor to get nanoseconds. */
if (g_rdFactor != 0.0)
return mach_absolute_time() * g_rdFactor;
/* worst case: fallback to gettimeofday(). */
}
{
return rtTimeGetSystemNanoTS();
}
{
return rtTimeGetSystemNanoTS() / 1000000;
}
{
/** @todo find nanosecond API for getting time of day. */
}