Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\nkern\win32\ncutilf.cpp
20 // Win32 fast counter implementation
22 static TBool FastCounterSupported = FALSE;
23 static TInt FastCounterShift;
24 static TInt FastCounterAdjustedFreq;
26 /** Initialise the fast counter.
28 Check whether a high performance counter is available and determine its
29 frequency. Work out a scaling that allows a 32 bit counter value that wraps
30 at most every 16 seconds.
32 void FastCounterInit()
34 // Test support by getting count - QueryPerformanceFrequency can succeed
35 // even if not supported
38 if (!QueryPerformanceCounter(&count) || count.QuadPart == 0)
39 return; // not supported
43 if (!QueryPerformanceFrequency(&freq) || freq.QuadPart == 0)
44 return; // not supported
46 TInt mso = __e32_find_ms1_32(freq.LowPart);
47 FastCounterShift = (mso > 27) ? mso - 27 : 0;
49 FastCounterSupported = TRUE;
50 FastCounterAdjustedFreq = freq.LowPart >> FastCounterShift;
53 /** Get the current value of the high performance counter.
55 If a high performance counter is not available, this uses the millisecond
58 EXPORT_C TUint32 NKern::FastCounter()
60 if (FastCounterSupported)
64 QueryPerformanceCounter(&count);
65 return (TUint32)(count.QuadPart >> FastCounterShift);
72 /** Get the frequency of counter queried by NKern::FastCounter().
74 EXPORT_C TInt NKern::FastCounterFrequency()
76 if (FastCounterSupported)
77 return FastCounterAdjustedFreq;
79 return 1000000 / TickPeriod();