Ignore:
Timestamp:
Nov 21, 2005 4:59:47 PM (18 years ago)
Author:
bennylp
Message:

Added rdtsc option for win32 timestamp and added pj_elapsed_msec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/os_timestamp_win32.c

    r66 r70  
    2121#include <windows.h> 
    2222 
     23#if defined(PJ_TIMESTAMP_USE_RDTSC) && PJ_TIMESTAMP_USE_RDTSC!=0 && \ 
     24    defined(PJ_M_I386) && PJ_M_I386 != 0 && \ 
     25    defined(_MSC_VER) 
     26/* 
     27 * Use rdtsc to get the OS timestamp. 
     28 */ 
     29static LONG CpuMhz; 
     30static pj_int64_t CpuHz; 
     31  
     32static pj_status_t GetCpuHz(void) 
     33{ 
     34    HKEY key; 
     35    LONG rc; 
     36    DWORD size; 
     37 
     38    rc = RegOpenKey( HKEY_LOCAL_MACHINE, 
     39                     "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 
     40                     &key); 
     41    if (rc != ERROR_SUCCESS) 
     42        return PJ_RETURN_OS_ERROR(rc); 
     43 
     44    size = sizeof(CpuMhz); 
     45    rc = RegQueryValueEx(key, "~MHz", NULL, NULL, (BYTE*)&CpuMhz, &size); 
     46    RegCloseKey(key); 
     47 
     48    if (rc != ERROR_SUCCESS) { 
     49        return PJ_RETURN_OS_ERROR(rc); 
     50    } 
     51 
     52    CpuHz = CpuMhz; 
     53    CpuHz = CpuHz * 1000000; 
     54 
     55    return PJ_SUCCESS; 
     56} 
     57 
     58/* __int64 is nicely returned in EDX:EAX */ 
     59__declspec(naked) __int64 rdtsc()  
     60{ 
     61    __asm  
     62    { 
     63        RDTSC 
     64        RET 
     65    } 
     66} 
     67 
     68PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) 
     69{ 
     70    ts->u64 = rdtsc(); 
     71    return PJ_SUCCESS; 
     72} 
     73 
     74PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq) 
     75{ 
     76    pj_status_t status; 
     77 
     78    if (CpuHz == 0) { 
     79        status = GetCpuHz(); 
     80        if (status != PJ_SUCCESS) 
     81            return status; 
     82    } 
     83 
     84    freq->u64 = CpuHz; 
     85    return PJ_SUCCESS; 
     86} 
     87 
     88#else 
     89/* 
     90 * Use QueryPerformanceCounter and QueryPerformanceFrequency. 
     91 */ 
    2392PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) 
    2493{ 
     
    43112} 
    44113 
     114#endif  /* PJ_TIMESTAMP_USE_RDTSC */ 
     115 
Note: See TracChangeset for help on using the changeset viewer.