Changeset abb46dc5e567405194af5603df0cd4ea85f7f23c
- 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
| rec37e0e |
rabb46dc |
|
| 129 | 129 | static unsigned prec = 0; |
|---|
| 130 | 130 | static volatile mtime_t cached_time = 0; |
|---|
| | 131 | #if (_POSIX_MONOTONIC_CLOCK - 0 < 0) |
|---|
| | 132 | # define CLOCK_MONOTONIC CLOCK_REALTIME |
|---|
| | 133 | #endif |
|---|
| 131 | 134 | |
|---|
| 132 | 135 | /** |
|---|
| … | … | |
| 143 | 146 | struct timespec ts; |
|---|
| 144 | 147 | |
|---|
| 145 | | # if (_POSIX_MONOTONIC_CLOCK - 0 >= 0) |
|---|
| 146 | 148 | /* 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 ) |
|---|
| 149 | 150 | /* Run-time fallback to real-time clock (always available) */ |
|---|
| 150 | 151 | (void)clock_gettime( CLOCK_REALTIME, &ts ); |
|---|
| … | … | |
| 263 | 264 | struct timespec ts = { d.quot, d.rem * 1000 }; |
|---|
| 264 | 265 | |
|---|
| 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 | } |
|---|
| 269 | 274 | #else |
|---|
| 270 | 275 | |
|---|
| … | … | |
| 290 | 295 | struct timespec ts = { d.quot, d.rem * 1000 }; |
|---|
| 291 | 296 | |
|---|
| 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 | } |
|---|
| 296 | 304 | |
|---|
| 297 | 305 | #elif defined( HAVE_KERNEL_OS_H ) |
|---|
| … | … | |
| 313 | 321 | ts_delay.tv_nsec = (delay % 1000000) * 1000; |
|---|
| 314 | 322 | |
|---|
| 315 | | nanosleep( &ts_delay, NULL ); |
|---|
| | 323 | while( nanosleep( &ts_delay, &ts_delay ) && ( errno == EINTR ) ); |
|---|
| 316 | 324 | |
|---|
| 317 | 325 | #else |
|---|
| … | … | |
| 321 | 329 | tv_delay.tv_usec = delay % 1000000; |
|---|
| 322 | 330 | |
|---|
| 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. */ |
|---|
| 327 | 333 | select( 0, NULL, NULL, NULL, &tv_delay ); |
|---|
| 328 | 334 | #endif |
|---|