]>
Commit | Line | Data |
---|---|---|
c7de829c WD |
1 | /**************************************************************************** |
2 | * | |
3 | * Ultra Long Period Timer | |
4 | * | |
5 | * ======================================================================== | |
6 | * | |
7 | * The contents of this file are subject to the SciTech MGL Public | |
8 | * License Version 1.0 (the "License"); you may not use this file | |
9 | * except in compliance with the License. You may obtain a copy of | |
10 | * the License at http://www.scitechsoft.com/mgl-license.txt | |
11 | * | |
12 | * Software distributed under the License is distributed on an | |
13 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
14 | * implied. See the License for the specific language governing | |
15 | * rights and limitations under the License. | |
16 | * | |
17 | * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc. | |
18 | * | |
19 | * The Initial Developer of the Original Code is SciTech Software, Inc. | |
20 | * All Rights Reserved. | |
21 | * | |
22 | * ======================================================================== | |
23 | * | |
24 | * Language: ANSI C | |
25 | * Environment: RTTarget-32 | |
26 | * | |
27 | * Description: Module to implement OS specific services to measure the | |
28 | * CPU frequency. | |
29 | * | |
30 | ****************************************************************************/ | |
31 | ||
32 | /*---------------------------- Global variables ---------------------------*/ | |
33 | ||
34 | static ibool havePerformanceCounter; | |
35 | ||
36 | /*----------------------------- Implementation ----------------------------*/ | |
37 | ||
38 | /**************************************************************************** | |
39 | REMARKS: | |
40 | Increase the thread priority to maximum, if possible. | |
41 | ****************************************************************************/ | |
42 | static int SetMaxThreadPriority(void) | |
43 | { | |
44 | int oldPriority; | |
45 | HANDLE hThread = GetCurrentThread(); | |
46 | ||
47 | oldPriority = GetThreadPriority(hThread); | |
48 | if (oldPriority != THREAD_PRIORITY_ERROR_RETURN) | |
8bde7f77 | 49 | SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL); |
c7de829c WD |
50 | return oldPriority; |
51 | } | |
52 | ||
53 | /**************************************************************************** | |
54 | REMARKS: | |
55 | Restore the original thread priority. | |
56 | ****************************************************************************/ | |
57 | static void RestoreThreadPriority( | |
58 | int oldPriority) | |
59 | { | |
60 | HANDLE hThread = GetCurrentThread(); | |
61 | ||
62 | if (oldPriority != THREAD_PRIORITY_ERROR_RETURN) | |
8bde7f77 | 63 | SetThreadPriority(hThread, oldPriority); |
c7de829c WD |
64 | } |
65 | ||
66 | /**************************************************************************** | |
67 | REMARKS: | |
68 | Initialise the counter and return the frequency of the counter. | |
69 | ****************************************************************************/ | |
70 | static void GetCounterFrequency( | |
71 | CPU_largeInteger *freq) | |
72 | { | |
73 | if (!QueryPerformanceFrequency((LARGE_INTEGER*)freq)) { | |
8bde7f77 WD |
74 | havePerformanceCounter = false; |
75 | freq->low = 100000; | |
76 | freq->high = 0; | |
77 | } | |
c7de829c | 78 | else |
8bde7f77 | 79 | havePerformanceCounter = true; |
c7de829c WD |
80 | } |
81 | ||
82 | /**************************************************************************** | |
83 | REMARKS: | |
84 | Read the counter and return the counter value. | |
85 | ****************************************************************************/ | |
86 | #define GetCounter(t) \ | |
87 | { \ | |
88 | if (havePerformanceCounter) \ | |
8bde7f77 | 89 | QueryPerformanceCounter((LARGE_INTEGER*)t); \ |
c7de829c | 90 | else { \ |
8bde7f77 WD |
91 | (t)->low = timeGetTime() * 100; \ |
92 | (t)->high = 0; \ | |
93 | } \ | |
c7de829c | 94 | } |