counter.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:2k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*****************************************************************************
  2.  *
  3.  * This program is free software ; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2 of the License, or
  6.  * (at your option) any later version.
  7.  *
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11.  * GNU General Public License for more details.
  12.  *
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this program; if not, write to the Free Software
  15.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  16.  *
  17.  * $Id: counter.c 271 2005-08-09 08:31:35Z picard $
  18.  *
  19.  ****************************************************************************/
  20. #include "../common/common.h"
  21. #include <windows.h>
  22. #include "counter.h"
  23. void (STDCALL *GetCounter)(int64_t*) = NULL;
  24. #if defined( MIPS)
  25. void STDCALL GetTimeCounter(int64_t* v)
  26. {
  27. SYSTEMTIME t;
  28. GetSystemTime(&t);
  29. *v = (t.wDay*24+t.wHour)*60*60*1000+(t.wMinute*60+t.wSecond)*1000+t.wMilliseconds;
  30. }
  31. #elif defined(TARGET_WINCE)
  32. void STDCALL GetTimeCounter(int64_t* v)
  33. {
  34. *v = GetTickCount();
  35. }
  36. #else
  37. void STDCALL GetTimeCounter(int64_t* v)
  38. {
  39. *v = timeGetTime();
  40. }
  41. #endif
  42. #if defined(TARGET_WINCE)
  43. static HANDLE CoreDLL = NULL;
  44. static BOOL (WINAPI* FuncQueryPerformanceCounter)(LARGE_INTEGER*) = NULL;
  45. static BOOL (WINAPI* FuncQueryPerformanceFrequency)(LARGE_INTEGER*) = NULL;
  46. #else
  47. #define FuncQueryPerformanceFrequency QueryPerformanceFrequency
  48. #define FuncQueryPerformanceCounter QueryPerformanceCounter
  49. #endif
  50. void BeginCounter(int64_t* p)
  51. {
  52. #if defined(TARGET_WINCE)
  53. CoreDLL = LoadLibrary(T("coredll.dll"));
  54. if (CoreDLL)
  55. {
  56. *(FARPROC*)&FuncQueryPerformanceCounter = GetProcAddress(CoreDLL,T("QueryPerformanceCounter"));
  57. *(FARPROC*)&FuncQueryPerformanceFrequency = GetProcAddress(CoreDLL,T("QueryPerformanceFrequency"));
  58. }
  59. #endif
  60. if (FuncQueryPerformanceFrequency && 
  61. FuncQueryPerformanceCounter &&
  62. FuncQueryPerformanceFrequency((LARGE_INTEGER*)p) && *p>5000)
  63. {
  64. GetCounter = (void(STDCALL*)(int64_t*)) QueryPerformanceCounter;
  65. }
  66. else
  67. {
  68. GetCounter = GetTimeCounter;
  69. *p = 1000;
  70. }
  71. }
  72. void EndCounter()
  73. {
  74. #if defined(TARGET_WINCE)
  75. if (CoreDLL) FreeLibrary(CoreDLL);
  76. #endif
  77. }