Changeset 3b6352d in rtems


Ignore:
Timestamp:
07/19/14 00:46:59 (9 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, 5, master
Children:
875fff0a
Parents:
8abbbdde
git-author:
Joel Sherrill <joel.sherrill@…> (07/19/14 00:46:59)
git-committer:
Joel Sherrill <joel.sherrill@…> (07/23/14 19:24:49)
Message:

adjtime.c: Use timestamp math and simplify

File:
1 edited

Legend:

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

    r8abbbdde r3b6352d  
    22 *  @file
    33 *
    4  *  @brief Correct the Time to Synchronize the System Clock
     4 *  @brief Adjust the Time to Synchronize the System Clock
    55 *  @ingroup POSIXAPI
    66 */
    77
    88/*
    9  *  COPYRIGHT (c) 1989-2007.
     9 *  COPYRIGHT (c) 1989-2014.
    1010 *  On-Line Applications Research Corporation (OAR).
    1111 *
     
    1919#endif
    2020
     21#define _BSD_SOURCE
    2122#include <time.h>
    2223#include <sys/time.h>
     
    3132/**
    3233 * This method was initially added as part of porting NTP to RTEMS.
    33  *  It is a BSD compatability function and now is available on
    34  *  GNU/Linux.
     34 * It is a BSD compatability function and now is available on
     35 * GNU/Linux.
    3536 *
    36  *  At one point there was a static variable named adjustment
    37  *  used by this implementation.  I don't see any reason for it
    38  *  to be here based upon the GNU/Linux documentation.
     37 * At one point there was a static variable named adjustment
     38 * used by this implementation.  I don't see any reason for it
     39 * to be here based upon the GNU/Linux documentation.
    3940 */
    40 int  adjtime(
     41int adjtime(
    4142  const struct timeval *delta,
    42   struct timeval *olddelta
     43  struct timeval       *olddelta
    4344)
    4445{
    45   struct timespec ts;
    46   long   adjustment;
     46  Timestamp_Control  delta_as_timestamp;
     47  Timestamp_Control  tod_as_timestamp;
     48  Timestamp_Control *tod_as_timestamp_ptr;
    4749
    4850  /*
     
    5254    rtems_set_errno_and_return_minus_one( EINVAL );
    5355
    54   if ( delta->tv_usec >= TOD_MICROSECONDS_PER_SECOND )
    55     rtems_set_errno_and_return_minus_one( EINVAL );
    56 
     56  /*
     57   * Currently, RTEMS does the adjustment in one movement.
     58   * Given interest, requirements, and sponsorship, a future
     59   * enhancement would be to adjust the time in smaller increments
     60   * at each clock tick. Until then, there is no outstanding
     61   * adjustment.
     62   */
    5763  if ( olddelta ) {
    5864    olddelta->tv_sec  = 0;
     
    6066  }
    6167
    62   /* convert delta to microseconds */
    63   adjustment  = (delta->tv_sec * TOD_MICROSECONDS_PER_SECOND);
    64   adjustment += delta->tv_usec;
    65 
    66   /* too small to account for */
    67   if ( adjustment < rtems_configuration_get_microseconds_per_tick() )
    68     return 0;
     68  /*
     69   * convert delta timeval to internal timestamp
     70   */
     71  _Timestamp_Set( &delta_as_timestamp, delta->tv_sec, delta->tv_usec * 1000 );
    6972
    7073  /*
     
    7477  _Thread_Disable_dispatch();
    7578
    76     _TOD_Get( &ts );
     79    tod_as_timestamp_ptr =
     80      _TOD_Get_with_nanoseconds( &tod_as_timestamp, &_TOD.now );
    7781
    78     ts.tv_sec  += delta->tv_sec;
    79     ts.tv_nsec += delta->tv_usec * TOD_NANOSECONDS_PER_MICROSECOND;
    8082
    81     /* if adjustment is too much positive */
    82     while ( ts.tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
    83       ts.tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
    84       ts.tv_sec++;
    85     }
     83    _Timestamp_Add_to( tod_as_timestamp_ptr, &delta_as_timestamp );
    8684
    87     /* if adjustment is too much negative */
    88     while ( ts.tv_nsec <= (-1 * TOD_NANOSECONDS_PER_SECOND) ) {
    89       ts.tv_nsec += TOD_NANOSECONDS_PER_SECOND;
    90       ts.tv_sec--;
    91     }
    92 
    93     _TOD_Set( &ts );
     85    _TOD_Set_with_timestamp( tod_as_timestamp_ptr );
    9486
    9587  _Thread_Enable_dispatch();
    9688
    97   /* set the user's output */
    98   if ( olddelta )
    99     *olddelta = *delta;
    100 
    10189  return 0;
    10290}
Note: See TracChangeset for help on using the changeset viewer.