Changeset 3456 for pjproject


Ignore:
Timestamp:
Mar 16, 2011 9:22:24 AM (13 years ago)
Author:
ming
Message:

Fixed #1211: Add pjlib API pj_gettickcount() that returns a monotonically increasing timestamp

  • Changed the timer_heap to use pj_gettickcount().
  • Changed ioqueue to use pj_gettickcount().
Location:
pjproject/trunk/pjlib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/os.h

    r3423 r3456  
    11701170 
    11711171/** 
     1172 * Get monotonic time since some unspecified starting point. 
     1173 * 
     1174 * @param tv    Variable to store the result. 
     1175 * 
     1176 * @return PJ_SUCCESS if successful. 
     1177 */ 
     1178PJ_DECL(pj_status_t) pj_gettickcount(pj_time_val *tv); 
     1179 
     1180/** 
    11721181 * Acquire high resolution timer value. The time value are stored 
    11731182 * in cycles. 
  • pjproject/trunk/pjlib/src/pj/ioqueue_epoll.c

    r2394 r3456  
    466466 
    467467        pj_assert(key->closing == 1); 
    468         pj_gettimeofday(&key->free_time); 
     468        pj_gettickcount(&key->free_time); 
    469469        key->free_time.msec += PJ_IOQUEUE_KEY_FREE_DELAY; 
    470470        pj_time_val_normalize(&key->free_time); 
     
    584584    pj_ioqueue_key_t *h; 
    585585 
    586     pj_gettimeofday(&now); 
     586    pj_gettickcount(&now); 
    587587    h = ioqueue->closing_list.next; 
    588588    while (h != &ioqueue->closing_list) { 
  • pjproject/trunk/pjlib/src/pj/ioqueue_select.c

    r3299 r3456  
    412412 
    413413        pj_assert(key->closing == 1); 
    414         pj_gettimeofday(&key->free_time); 
     414        pj_gettickcount(&key->free_time); 
    415415        key->free_time.msec += PJ_IOQUEUE_KEY_FREE_DELAY; 
    416416        pj_time_val_normalize(&key->free_time); 
     
    609609    pj_ioqueue_key_t *h; 
    610610 
    611     pj_gettimeofday(&now); 
     611    pj_gettickcount(&now); 
    612612    h = ioqueue->closing_list.next; 
    613613    while (h != &ioqueue->closing_list) { 
  • pjproject/trunk/pjlib/src/pj/ioqueue_winnt.c

    r3051 r3456  
    620620 
    621621        pj_assert(key->closing == 1); 
    622         pj_gettimeofday(&key->free_time); 
     622        pj_gettickcount(&key->free_time); 
    623623        key->free_time.msec += PJ_IOQUEUE_KEY_FREE_DELAY; 
    624624        pj_time_val_normalize(&key->free_time); 
     
    875875        pj_ioqueue_key_t *key; 
    876876 
    877         pj_gettimeofday(&now); 
     877        pj_gettickcount(&now); 
    878878         
    879879        /* Move closing keys to free list when they've finished the closing 
  • pjproject/trunk/pjlib/src/pj/os_timestamp_common.c

    r2560 r3456  
    189189} 
    190190 
     191PJ_DEF(pj_status_t) pj_gettickcount(pj_time_val *tv) 
     192{ 
     193    pj_timestamp ts, start; 
     194    pj_status_t status; 
     195 
     196    if ((status = pj_get_timestamp(&ts)) != PJ_SUCCESS) 
     197        return status; 
     198 
     199    pj_set_timestamp32(&start, 0, 0); 
     200    *tv = pj_elapsed_time(&start, &ts); 
     201 
     202    return PJ_SUCCESS; 
     203} 
     204 
    191205#endif  /* PJ_HAS_HIGH_RES_TIMER */ 
    192206 
  • pjproject/trunk/pjlib/src/pj/os_timestamp_posix.c

    r2394 r3456  
    2525#include <ctype.h> 
    2626 
     27#if defined(PJ_HAS_UNISTD_H) && PJ_HAS_UNISTD_H != 0 
     28#   include <unistd.h> 
     29 
     30#   if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && \ 
     31       defined(_POSIX_MONOTONIC_CLOCK) 
     32#       define USE_POSIX_TIMERS 1 
     33#   endif 
     34 
     35#endif 
     36 
    2737#if defined(PJ_HAS_PENTIUM) && PJ_HAS_PENTIUM!=0 && \ 
    2838    defined(PJ_TIMESTAMP_USE_RDTSC) && PJ_TIMESTAMP_USE_RDTSC!=0 && \ 
     
    111121} 
    112122 
     123#elif defined(PJ_DARWINOS) && PJ_DARWINOS != 0 
     124#include <mach/mach.h> 
     125#include <mach/clock.h> 
     126#include <errno.h> 
     127 
     128#define NSEC_PER_SEC    1000000000 
     129 
     130PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) 
     131{ 
     132    mach_timespec_t tp; 
     133    int ret; 
     134    clock_serv_t serv; 
     135 
     136    ret = host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &serv); 
     137    if (ret != KERN_SUCCESS) { 
     138        return PJ_RETURN_OS_ERROR(EINVAL); 
     139    } 
     140 
     141    ret = clock_get_time(serv, &tp); 
     142    if (ret != KERN_SUCCESS) { 
     143        return PJ_RETURN_OS_ERROR(EINVAL); 
     144    } 
     145 
     146    ts->u64 = tp.tv_sec; 
     147    ts->u64 *= NSEC_PER_SEC; 
     148    ts->u64 += tp.tv_nsec; 
     149 
     150    return PJ_SUCCESS; 
     151} 
     152 
     153PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq) 
     154{ 
     155    freq->u32.hi = 0; 
     156    freq->u32.lo = NSEC_PER_SEC; 
     157 
     158    return PJ_SUCCESS; 
     159} 
     160 
     161#elif defined(USE_POSIX_TIMERS) && USE_POSIX_TIMERS != 0 
     162#include <sys/time.h> 
     163#include <errno.h> 
     164 
     165#define NSEC_PER_SEC    1000000000 
     166 
     167PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) 
     168{ 
     169    struct timespec tp; 
     170 
     171    if (clock_gettime(CLOCK_MONOTONIC, &tp) != 0) { 
     172        return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 
     173    } 
     174 
     175    ts->u64 = tp.tv_sec; 
     176    ts->u64 *= NSEC_PER_SEC; 
     177    ts->u64 += tp.tv_nsec; 
     178 
     179    return PJ_SUCCESS; 
     180} 
     181 
     182PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq) 
     183{ 
     184    freq->u32.hi = 0; 
     185    freq->u32.lo = NSEC_PER_SEC; 
     186 
     187    return PJ_SUCCESS; 
     188} 
     189 
    113190#else 
    114191#include <sys/time.h> 
     
    141218 
    142219#endif 
    143  
  • pjproject/trunk/pjlib/src/pj/symbols.c

    r2394 r3456  
    198198PJ_EXPORT_SYMBOL(pj_time_decode) 
    199199#if defined(PJ_HAS_HIGH_RES_TIMER) && PJ_HAS_HIGH_RES_TIMER != 0 
     200PJ_EXPORT_SYMBOL(pj_gettickcount) 
    200201PJ_EXPORT_SYMBOL(pj_get_timestamp) 
    201202PJ_EXPORT_SYMBOL(pj_get_timestamp_freq) 
  • pjproject/trunk/pjlib/src/pj/timer.c

    r1672 r3456  
    466466    PJ_ASSERT_RETURN(entry->_timer_id < 1, PJ_EINVALIDOP); 
    467467 
    468     pj_gettimeofday(&expires); 
     468    pj_gettickcount(&expires); 
    469469    PJ_TIME_VAL_ADD(expires, *delay); 
    470470     
     
    504504 
    505505    count = 0; 
    506     pj_gettimeofday(&now); 
     506    pj_gettickcount(&now); 
    507507 
    508508    lock_timer_heap(ht); 
Note: See TracChangeset for help on using the changeset viewer.