Changeset abb46dc5e567405194af5603df0cd4ea85f7f23c

Show
Ignore:
Timestamp:
02/03/07 17:17:30 (2 years ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1172852250 +0000
git-parent:

[898c9279c74f6cda95a8c96d5204b7cc605aa92e]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1172852250 +0000
Message:

Fix handling of EINTR in sleeping functions.
This will not change your life.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/misc/mtime.c

    rec37e0e rabb46dc  
    129129static unsigned prec = 0; 
    130130static volatile mtime_t cached_time = 0; 
     131#if (_POSIX_MONOTONIC_CLOCK - 0 < 0) 
     132# define CLOCK_MONOTONIC CLOCK_REALTIME 
     133#endif 
    131134 
    132135/** 
     
    143146    struct timespec ts; 
    144147 
    145 # if (_POSIX_MONOTONIC_CLOCK - 0 >= 0) 
    146148    /* Try to use POSIX monotonic clock if available */ 
    147     if( clock_gettime( CLOCK_MONOTONIC, &ts ) ) 
    148 # endif 
     149    if( clock_gettime( CLOCK_MONOTONIC, &ts ) == EINVAL ) 
    149150        /* Run-time fallback to real-time clock (always available) */ 
    150151        (void)clock_gettime( CLOCK_REALTIME, &ts ); 
     
    263264    struct timespec ts = { d.quot, d.rem * 1000 }; 
    264265 
    265 # if (_POSIX_MONOTONIC_CLOCK - 0 >= 0) 
    266     if( clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL ) ) 
    267 # endif 
    268         clock_nanosleep( CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL ); 
     266    int val; 
     267    while( ( val = clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, 
     268                                    NULL ) ) == EINTR ); 
     269    if( val == EINVAL ) 
     270    { 
     271        ts.tv_sec = d.quot; ts.tv_nsec = d.rem * 1000; 
     272        while( clock_nanosleep( CLOCK_REALTIME, 0, &ts, NULL ) == EINTR ); 
     273    } 
    269274#else 
    270275 
     
    290295    struct timespec ts = { d.quot, d.rem * 1000 }; 
    291296 
    292 # if (_POSIX_MONOTONIC_CLOCK - 0 >= 0) 
    293     if( clock_nanosleep( CLOCK_MONOTONIC, 0, &ts, NULL ) ) 
    294 # endif 
    295         clock_nanosleep( CLOCK_REALTIME, 0, &ts, NULL ); 
     297    int val; 
     298    while( ( val = clock_nanosleep( CLOCK_MONOTONIC, 0, &ts, &ts ) ) == EINTR ); 
     299    if( val == EINVAL ) 
     300    { 
     301        ts.tv_sec = d.quot; ts.tv_nsec = d.rem * 1000; 
     302        while( clock_nanosleep( CLOCK_REALTIME, 0, &ts, &ts ) == EINTR ); 
     303    } 
    296304 
    297305#elif defined( HAVE_KERNEL_OS_H ) 
     
    313321    ts_delay.tv_nsec = (delay % 1000000) * 1000; 
    314322 
    315     nanosleep( &ts_delay, NULL ); 
     323    while( nanosleep( &ts_delay, &ts_delay ) && ( errno == EINTR ) ); 
    316324 
    317325#else 
     
    321329    tv_delay.tv_usec = delay % 1000000; 
    322330 
    323     /* select() return value should be tested, since several possible errors 
    324      * can occur. However, they should only happen in very particular occasions 
    325      * (i.e. when a signal is sent to the thread, or when memory is full), and 
    326      * can be ignored. */ 
     331    /* If a signal is caught, you are screwed. Update your OS to nanosleep() 
     332     * or clock_nanosleep() if this is an issue. */ 
    327333    select( 0, NULL, NULL, NULL, &tv_delay ); 
    328334#endif