Changeset 3e81d52 in rtems


Ignore:
Timestamp:
Oct 29, 2017, 7:29:05 PM (19 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
a54d10d
Parents:
8c1f4064
git-author:
Sebastian Huber <sebastian.huber@…> (10/29/17 19:29:05)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/02/17 13:08:32)
Message:

posix: Use far future for very long timeouts

Close #3205.

Files:
4 edited

Legend:

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

    r8c1f4064 r3e81d52  
    6464{
    6565  Thread_queue_Context   queue_context;
    66   struct timespec        spare_end;
     66  struct timespec        uptime;
    6767  const struct timespec *end;
    6868  Thread_Control        *executing;
     
    9494    }
    9595  } else {
    96     if ( !_Watchdog_Is_valid_interval_timespec( rqtp ) ) {
    97       return EINVAL;
    98     }
    99 
    100     _TOD_Get_zero_based_uptime_as_timespec( &spare_end );
    101 
    102     /* In case this overflows, then the enqueue callout will reject it */
    103     _Timespec_Add_to( &spare_end, rqtp );
    104 
    105     end = &spare_end;
     96    _TOD_Get_zero_based_uptime_as_timespec( &uptime );
     97    end = _Watchdog_Future_timespec( &uptime, rqtp );
    10698    _Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(
    10799      &queue_context,
  • cpukit/posix/src/sigtimedwait.c

    r8c1f4064 r3e81d52  
    7777  siginfo_t            *the_info;
    7878  int                   signo;
     79  struct timespec       uptime;
    7980  Thread_queue_Context  queue_context;
    8081  int                   error;
     
    9394
    9495  if ( timeout != NULL ) {
    95     struct timespec end;
    96 
    97     if ( !_Watchdog_Is_valid_interval_timespec( timeout ) ) {
    98       return EINVAL;
    99     }
    100 
    101     _TOD_Get_zero_based_uptime_as_timespec( &end );
    102 
    103     /* In case this overflows, then the enqueue callout will reject it */
    104     _Timespec_Add_to( &end, timeout );
    105 
     96    const struct timespec *end;
     97
     98    _TOD_Get_zero_based_uptime_as_timespec( &uptime );
     99    end = _Watchdog_Future_timespec( &uptime, timeout );
    106100    _Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(
    107101      &queue_context,
    108       &end
     102      end
    109103    );
    110104  } else {
  • cpukit/score/include/rtems/score/watchdogimpl.h

    r8c1f4064 r3e81d52  
    325325}
    326326
     327RTEMS_INLINE_ROUTINE const struct timespec * _Watchdog_Future_timespec(
     328  struct timespec       *now,
     329  const struct timespec *delta
     330)
     331{
     332  uint64_t sec;
     333
     334  if ( !_Watchdog_Is_valid_interval_timespec( delta ) ) {
     335    return NULL;
     336  }
     337
     338  sec = (uint64_t) now->tv_sec;
     339  sec += (uint64_t) delta->tv_sec;
     340  now->tv_nsec += delta->tv_nsec;
     341
     342  /* We have 2 * (2**63 - 1) + 1 == UINT64_MAX */
     343  if ( now->tv_nsec >= WATCHDOG_NANOSECONDS_PER_SECOND ) {
     344    now->tv_nsec -= WATCHDOG_NANOSECONDS_PER_SECOND;
     345    ++sec;
     346  }
     347
     348  if ( sec <= INT64_MAX ) {
     349    now->tv_sec = sec;
     350  } else {
     351    now->tv_sec = INT64_MAX;
     352  }
     353
     354  return now;
     355}
     356
    327357RTEMS_INLINE_ROUTINE bool _Watchdog_Is_far_future_monotonic_timespec(
    328358  const struct timespec *ts
  • testsuites/psxtests/psxclock/init.c

    r8c1f4064 r3e81d52  
    1414#include <time.h>
    1515#include <errno.h>
     16#include <stdint.h>
    1617
    1718#include "pmacros.h"
    1819#include "pritime.h"
    1920
     21#include <rtems.h>
    2022#include <rtems/score/todimpl.h>
    2123
    2224const char rtems_test_name[] = "PSXCLOCK";
    2325
    24 /* forward declarations to avoid warnings */
    25 rtems_task Init(rtems_task_argument argument);
    26 void check_enosys(int status);
    27 
    28 void check_enosys(int status)
     26static void check_enosys(int status)
    2927{
    3028  if ( (status == -1) && (errno == ENOSYS) )
     
    3432}
    3533
    36 rtems_task Init(
     34typedef struct {
     35  int counter;
     36  struct timespec delta;
     37} nanosleep_contex;
     38
     39static void task_nanosleep( rtems_task_argument arg )
     40{
     41  nanosleep_contex *ctx;
     42
     43  ctx = (nanosleep_contex *) arg;
     44  ++ctx->counter;
     45  nanosleep( &ctx->delta, NULL );
     46}
     47
     48static void test_far_future_nanosleep( void )
     49{
     50  rtems_status_code sc;
     51  rtems_id          id;
     52  nanosleep_contex  ctx;
     53
     54  sc = rtems_task_create(
     55    rtems_build_name( 'N', 'A', 'N', 'O' ),
     56    1,
     57    RTEMS_MINIMUM_STACK_SIZE,
     58    RTEMS_DEFAULT_MODES,
     59    RTEMS_DEFAULT_ATTRIBUTES,
     60    &id
     61  );
     62  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     63
     64  ctx.counter = 0;
     65  ctx.delta.tv_sec = INT64_MAX;
     66  ctx.delta.tv_nsec = 999999999;
     67  sc = rtems_task_start( id, task_nanosleep, (rtems_task_argument) &ctx );
     68  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     69
     70  sc = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
     71  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     72
     73  rtems_test_assert( ctx.counter == 1 );
     74
     75  sc = rtems_task_delete( id );
     76  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     77}
     78
     79static rtems_task Init(
    3780  rtems_task_argument argument
    3881)
     
    141184  rtems_test_assert( !remaining );
    142185
     186  test_far_future_nanosleep();
     187
    143188  /* error cases in nanosleep */
    144189
     
    268313
    269314#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
    270 #define CONFIGURE_MAXIMUM_TASKS             1
     315#define CONFIGURE_MAXIMUM_TASKS             2
    271316
    272317#define CONFIGURE_INIT
Note: See TracChangeset for help on using the changeset viewer.