| 1 |
/* Copyright: © Copyright 2005 Apple Computer, Inc. All rights reserved. |
|---|
| 2 |
|
|---|
| 3 |
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. |
|---|
| 4 |
("Apple") in consideration of your agreement to the following terms, and your |
|---|
| 5 |
use, installation, modification or redistribution of this Apple software |
|---|
| 6 |
constitutes acceptance of these terms. If you do not agree with these terms, |
|---|
| 7 |
please do not use, install, modify or redistribute this Apple software. |
|---|
| 8 |
|
|---|
| 9 |
In consideration of your agreement to abide by the following terms, and subject |
|---|
| 10 |
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs |
|---|
| 11 |
copyrights in this original Apple software (the "Apple Software"), to use, |
|---|
| 12 |
reproduce, modify and redistribute the Apple Software, with or without |
|---|
| 13 |
modifications, in source and/or binary forms; provided that if you redistribute |
|---|
| 14 |
the Apple Software in its entirety and without modifications, you must retain |
|---|
| 15 |
this notice and the following text and disclaimers in all such redistributions of |
|---|
| 16 |
the Apple Software. Neither the name, trademarks, service marks or logos of |
|---|
| 17 |
Apple Computer, Inc. may be used to endorse or promote products derived from the |
|---|
| 18 |
Apple Software without specific prior written permission from Apple. Except as |
|---|
| 19 |
expressly stated in this notice, no other rights or licenses, express or implied, |
|---|
| 20 |
are granted by Apple herein, including but not limited to any patent rights that |
|---|
| 21 |
may be infringed by your derivative works or by other works in which the Apple |
|---|
| 22 |
Software may be incorporated. |
|---|
| 23 |
|
|---|
| 24 |
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO |
|---|
| 25 |
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED |
|---|
| 26 |
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 27 |
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN |
|---|
| 28 |
COMBINATION WITH YOUR PRODUCTS. |
|---|
| 29 |
|
|---|
| 30 |
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR |
|---|
| 31 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
|---|
| 32 |
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|---|
| 33 |
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION |
|---|
| 34 |
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT |
|---|
| 35 |
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN |
|---|
| 36 |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 37 |
*/ |
|---|
| 38 |
/*============================================================================= |
|---|
| 39 |
CAHostTimeBase.cp |
|---|
| 40 |
|
|---|
| 41 |
=============================================================================*/ |
|---|
| 42 |
|
|---|
| 43 |
//============================================================================= |
|---|
| 44 |
// Includes |
|---|
| 45 |
//============================================================================= |
|---|
| 46 |
|
|---|
| 47 |
#include "CAHostTimeBase.h" |
|---|
| 48 |
|
|---|
| 49 |
Float64 CAHostTimeBase::sFrequency = 0; |
|---|
| 50 |
UInt32 CAHostTimeBase::sMinDelta = 0; |
|---|
| 51 |
UInt32 CAHostTimeBase::sToNanosNumerator = 0; |
|---|
| 52 |
UInt32 CAHostTimeBase::sToNanosDenominator = 0; |
|---|
| 53 |
UInt32 CAHostTimeBase::sFromNanosNumerator = 0; |
|---|
| 54 |
UInt32 CAHostTimeBase::sFromNanosDenominator = 0; |
|---|
| 55 |
bool CAHostTimeBase::sUseMicroseconds = false; |
|---|
| 56 |
bool CAHostTimeBase::sIsInited = false; |
|---|
| 57 |
#if Track_Host_TimeBase |
|---|
| 58 |
UInt64 CAHostTimeBase::sLastTime = 0; |
|---|
| 59 |
#endif |
|---|
| 60 |
|
|---|
| 61 |
//============================================================================= |
|---|
| 62 |
// CAHostTimeBase |
|---|
| 63 |
// |
|---|
| 64 |
// This class provides platform independent access to the host's time base. |
|---|
| 65 |
//============================================================================= |
|---|
| 66 |
|
|---|
| 67 |
void CAHostTimeBase::Initialize() |
|---|
| 68 |
{ |
|---|
| 69 |
// get the info about Absolute time |
|---|
| 70 |
#if TARGET_OS_MAC |
|---|
| 71 |
struct mach_timebase_info theTimeBaseInfo; |
|---|
| 72 |
mach_timebase_info(&theTimeBaseInfo); |
|---|
| 73 |
sMinDelta = 1; |
|---|
| 74 |
sToNanosNumerator = theTimeBaseInfo.numer; |
|---|
| 75 |
sToNanosDenominator = theTimeBaseInfo.denom; |
|---|
| 76 |
sFromNanosNumerator = sToNanosDenominator; |
|---|
| 77 |
sFromNanosDenominator = sToNanosNumerator; |
|---|
| 78 |
|
|---|
| 79 |
// the frequency of that clock is: (sToNanosDenominator / sToNanosNumerator) * 10^9 |
|---|
| 80 |
sFrequency = static_cast<Float64>(sToNanosDenominator) / static_cast<Float64>(sToNanosNumerator); |
|---|
| 81 |
sFrequency *= 1000000000.0; |
|---|
| 82 |
#elif TARGET_OS_WIN32 |
|---|
| 83 |
LARGE_INTEGER theFrequency; |
|---|
| 84 |
QueryPerformanceFrequency(&theFrequency); |
|---|
| 85 |
sMinDelta = 1; |
|---|
| 86 |
sToNanosNumerator = 1000000000ULL; |
|---|
| 87 |
sToNanosDenominator = *((UInt64*)&theFrequency); |
|---|
| 88 |
sFromNanosNumerator = sToNanosDenominator; |
|---|
| 89 |
sFromNanosDenominator = sToNanosNumerator; |
|---|
| 90 |
sFrequency = static_cast<Float64>(*((UInt64*)&theFrequency)); |
|---|
| 91 |
#endif |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
#if Log_Host_Time_Base_Parameters |
|---|
| 95 |
DebugMessage( "Host Time Base Parameters"); |
|---|
| 96 |
DebugMessageN1(" Minimum Delta: %lu", sMinDelta); |
|---|
| 97 |
DebugMessageN1(" Frequency: %f", sFrequency); |
|---|
| 98 |
DebugMessageN1(" To Nanos Numerator: %lu", sToNanosNumerator); |
|---|
| 99 |
DebugMessageN1(" To Nanos Denominator: %lu", sToNanosDenominator); |
|---|
| 100 |
DebugMessageN1(" From Nanos Numerator: %lu", sFromNanosNumerator); |
|---|
| 101 |
DebugMessageN1(" From Nanos Denominator: %lu", sFromNanosDenominator); |
|---|
| 102 |
#endif |
|---|
| 103 |
|
|---|
| 104 |
sIsInited = true; |
|---|
| 105 |
} |
|---|