Changeset d937d36 in rtems


Ignore:
Timestamp:
Mar 11, 2015, 8:53:44 PM (5 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, master
Children:
f1b4680
Parents:
b0f8bb4e
git-author:
Joel Sherrill <joel.sherrill@…> (03/11/15 20:53:44)
git-committer:
Joel Sherrill <joel.sherrill@…> (03/12/15 18:33:36)
Message:

posix/src/nanosleep.c: Address issue when delay is longer than desired

This resulted in the elapsed time going below 0 and an arbitrarily large
number returned as the time remaining.

closes #2296.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/src/nanosleep.c

    rb0f8bb4e rd937d36  
    22 * @file
    33 *
    4  * @brief Suspends Execution of calling thread until Time elaps
     4 * @brief Suspends Execution of calling thread until Time elapses
    55 * @ingroup POSIXAPI
    66 */
    77
    88/*
    9  *  COPYRIGHT (c) 1989-2007.
     9 *  COPYRIGHT (c) 1989-2015.
    1010 *  On-Line Applications Research Corporation (OAR).
    1111 *
     
    3030 *  14.2.5 High Resolution Sleep, P1003.1b-1993, p. 269
    3131 */
    32 
    3332int nanosleep(
    3433  const struct timespec  *rqtp,
     
    4342
    4443  Watchdog_Interval  ticks;
     44  Watchdog_Interval  elapsed;
    4545
    4646
     
    5454    rtems_set_errno_and_return_minus_one( EINVAL );
    5555
     56  /*
     57   * Convert the timespec delay into the appropriate number of clock ticks.
     58   */
    5659  ticks = _Timespec_To_ticks( rqtp );
    5760
     
    6164   *  consistent with the RTEMS API and yields desirable behavior.
    6265   */
    63 
    6466  if ( !ticks ) {
    6567    _Thread_Disable_dispatch();
     
    9294  _Thread_Enable_dispatch();
    9395
    94   /* calculate time remaining */
     96  /*
     97   * Calculate the time that passed while we were sleeping and how
     98   * much remains from what we requested.
     99   */
     100  elapsed = executing->Timer.stop_time - executing->Timer.start_time;
     101  if ( elapsed >= ticks )
     102    ticks = 0;
     103  else
     104    ticks -= elapsed;
    95105
     106  /*
     107   * If the user wants the time remaining, do the conversion.
     108   */
    96109  if ( rmtp ) {
    97     ticks -= executing->Timer.stop_time - executing->Timer.start_time;
     110    _Timespec_From_ticks( ticks, rmtp );
     111  }
    98112
    99     _Timespec_From_ticks( ticks, rmtp );
    100 
     113  /*
     114   *  Only when POSIX is enabled, can a sleep be interrupted.
     115   */
     116  #if defined(RTEMS_POSIX_API)
    101117    /*
    102      *  Only when POSIX is enabled, can a sleep be interrupted.
     118     *  If there is time remaining, then we were interrupted by a signal.
    103119     */
    104     #if defined(RTEMS_POSIX_API)
    105         /*
    106          *  If there is time remaining, then we were interrupted by a signal.
    107          */
    108         if ( ticks )
    109           rtems_set_errno_and_return_minus_one( EINTR );
    110     #endif
    111   }
     120    if ( ticks )
     121      rtems_set_errno_and_return_minus_one( EINTR );
     122  #endif
    112123
    113124  return 0;
Note: See TracChangeset for help on using the changeset viewer.