diff options
Diffstat (limited to 'cpukit/posix/src/semtimedwait.c')
-rw-r--r-- | cpukit/posix/src/semtimedwait.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/cpukit/posix/src/semtimedwait.c b/cpukit/posix/src/semtimedwait.c index 6acb704f7c..b0cb78deca 100644 --- a/cpukit/posix/src/semtimedwait.c +++ b/cpukit/posix/src/semtimedwait.c @@ -35,34 +35,37 @@ int sem_timedwait( /* * The abstime is a walltime. We turn it into an interval. */ - Watchdog_Interval ticks; - struct timespec current_time; - struct timespec difference; + Watchdog_Interval ticks = 0; + struct timespec current_time; + struct timespec difference; + Core_semaphore_Blocking_option blocking = CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT; /* * Error check the absolute time to timeout */ +#if 0 if ( /* abstime->tv_sec < 0 || */ abstime->tv_nsec ) /* tv_sec is unsigned */ - return EINVAL; - + blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE; + else +#endif if ( abstime->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) - return EINVAL; - - (void) clock_gettime( CLOCK_REALTIME, ¤t_time ); - - /* - * Make sure the abstime is in the future - */ - if ( abstime->tv_sec < current_time.tv_sec ) - return EINVAL; - if ( (abstime->tv_sec == current_time.tv_sec) && - (abstime->tv_nsec <= current_time.tv_nsec) ) - return EINVAL; - - _POSIX_Timespec_subtract( ¤t_time, abstime, &difference ); + blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE; + else { + (void) clock_gettime( CLOCK_REALTIME, ¤t_time ); + /* + * Make sure the abstime is in the future + */ + if ( abstime->tv_sec < current_time.tv_sec ) + blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE; + else if ( (abstime->tv_sec == current_time.tv_sec) && + (abstime->tv_nsec <= current_time.tv_nsec) ) + blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE; + else { + _POSIX_Timespec_subtract( ¤t_time, abstime, &difference ); + ticks = _POSIX_Timespec_to_interval( &difference ); + blocking = CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT; + } + } - ticks = _POSIX_Timespec_to_interval( &difference ); - - return _POSIX_Semaphore_Wait_support( sem, TRUE, ticks ); + return _POSIX_Semaphore_Wait_support( sem, blocking, ticks ); } - |