Changeset 2172 for trunk

Show
Ignore:
Timestamp:
06/25/12 07:11:38 (12 years ago)
Author:
jwoithe
Message:

Further work on ticket #242. It turns out that clock_nanosleep() isn't implemented when the specified clock is CLOCK_MONOTONIC_RAW. If called with CLOCK_MONOTONIC_RAW it returns straight away and this not surprisingly causes havoc for FFADO's timing. For now, use CLOCK_MONOTONIC as clock_nanosleep()'s clock when FFADO's system clock source is CLOCK_MONOTONIC_RAW. This may need revision if real-world testing demonstrates problems with this approach.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/libutil/SystemTimeSource.cpp

    r2171 r2172  
    7272    ts.tv_sec = usecs / (1000000LL); 
    7373    ts.tv_nsec = (usecs % (1000000LL)) * 1000LL; 
    74     clock_nanosleep(clock_id, 0, &ts, NULL); 
     74 
     75    // clock_nanosleep() is not implemented for CLOCK_MONOTONIC_RAW. 
     76    // If the clock source is CLOCK_MONOTONIC_RAW, use CLOCK_MONOTONIC 
     77    // as an approximation for the purposes of sleep timing. 
     78    clockid_t clk = (clock_id==CLOCK_MONOTONIC_RAW)?CLOCK_MONOTONIC:clock_id; 
     79 
     80    clock_nanosleep(clk, 0, &ts, NULL); 
    7581} 
    7682 
     
    7985{ 
    8086#if USE_ABSOLUTE_NANOSLEEP 
     87    // CLOCK_MONOTONIC_RAW isn't supported by clock_nanosleep() 
     88    clockid_t clk = (clock_id==CLOCK_MONOTONIC_RAW)?CLOCK_MONOTONIC:clock_id; 
    8189    struct timespec ts; 
    8290    ts.tv_sec = wake_at_usec / (1000000LL); 
     
    8593                       "clock_nanosleep until %"PRId64" sec, %"PRId64" nanosec\n", 
    8694                       (int64_t)ts.tv_sec, (int64_t)ts.tv_nsec); 
    87     int err = clock_nanosleep(clock_id, TIMER_ABSTIME, &ts, NULL); 
     95    int err = clock_nanosleep(clk, TIMER_ABSTIME, &ts, NULL); 
    8896    if(err) { 
    8997        // maybe signal occurred, but we're going to ignore that