Changeset f5c9b89 in rtems


Ignore:
Timestamp:
Oct 30, 2006, 10:21:07 PM (13 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Children:
ae54141
Parents:
d233c88
Message:

2006-10-30 Joel Sherrill <joel@…>

PR 841/rtems

  • itron/inline/rtems/itron/semaphore.inl, itron/macros/rtems/itron/semaphore.inl, itron/src/twai_sem.c, posix/include/rtems/posix/semaphore.h, posix/inline/rtems/posix/semaphore.inl, posix/src/semaphorewaitsupp.c, posix/src/semtimedwait.c, posix/src/semwait.c, rtems/src/semobtain.c, rtems/src/semtranslatereturncode.c, score/include/rtems/score/coresem.h, score/src/coresemseize.c: Make sem_timedwait more conformant to Open Group specification.
Location:
cpukit
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rd233c88 rf5c9b89  
     12006-10-30      Joel Sherrill <joel@OARcorp.com>
     2
     3        PR 841/rtems
     4        * itron/inline/rtems/itron/semaphore.inl,
     5        itron/macros/rtems/itron/semaphore.inl, itron/src/twai_sem.c,
     6        posix/include/rtems/posix/semaphore.h,
     7        posix/inline/rtems/posix/semaphore.inl,
     8        posix/src/semaphorewaitsupp.c, posix/src/semtimedwait.c,
     9        posix/src/semwait.c, rtems/src/semobtain.c,
     10        rtems/src/semtranslatereturncode.c,
     11        score/include/rtems/score/coresem.h, score/src/coresemseize.c: Make
     12        sem_timedwait more conformant to Open Group specification.
     13
    1142006-10-25      Jennifer Averett <jennifer@oarcorp.com>
    215
  • cpukit/itron/inline/rtems/itron/semaphore.inl

    rd233c88 rf5c9b89  
    173173    case CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED:
    174174      return E_QOVR;
     175    case CORE_SEMAPHORE_BAD_TIMEOUT_VALUE:
     176      return E_PAR;
    175177    case THREAD_STATUS_PROXY_BLOCKING:
    176178      return THREAD_STATUS_PROXY_BLOCKING;
  • cpukit/itron/macros/rtems/itron/semaphore.inl

    rd233c88 rf5c9b89  
    9292    case CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED:
    9393      return E_QOVR;
     94    case CORE_SEMAPHORE_BAD_TIMEOUT_VALUE:
     95      return E_PAR;
    9496    case THREAD_STATUS_PROXY_BLOCKING:
    9597      return THREAD_STATUS_PROXY_BLOCKING;
  • cpukit/itron/src/twai_sem.c

    rd233c88 rf5c9b89  
    3131)
    3232{
    33   ITRON_Semaphore_Control *the_semaphore;
    34   Objects_Locations        location;
    35   Watchdog_Interval        interval;
    36   boolean                  wait;
    37   CORE_semaphore_Status    status;
     33  ITRON_Semaphore_Control        *the_semaphore;
     34  Objects_Locations               location;
     35  Watchdog_Interval               interval;
     36  Core_semaphore_Blocking_option  blocking;
    3837
    3938  interval = 0;
    4039  if ( tmout == TMO_POL ) {
    41     wait = FALSE;
     40    blocking = CORE_SEMAPHORE_NO_WAIT;
    4241  } else {
    43     wait = TRUE;
     42    blocking = CORE_SEMAPHORE_BLOCK_FOREVER;
     43
    4444    if ( tmout != TMO_FEVR )
    4545      interval = TOD_MILLISECONDS_TO_TICKS(tmout);
     46
     47    if ( _ITRON_Is_in_non_task_state() )
     48      return E_CTX;
    4649  }
    47 
    48   if ( wait && _ITRON_Is_in_non_task_state() )
    49     return E_CTX;
    5050
    5151  the_semaphore = _ITRON_Semaphore_Get( semid, &location );
     
    5959        &the_semaphore->semaphore,
    6060        the_semaphore->Object.id,
    61         wait,                           /* wait for a timeout */
     61        blocking,                       /* wait for a timeout */
    6262        interval                        /* timeout value */
    6363      );
    6464      _Thread_Enable_dispatch();
    65       status = (CORE_semaphore_Status) _Thread_Executing->Wait.return_code;
    66       return _ITRON_Semaphore_Translate_core_semaphore_return_code( status );
     65      return _ITRON_Semaphore_Translate_core_semaphore_return_code(
     66               _Thread_Executing->Wait.return_code
     67             );
    6768  }
    6869  return E_OK;
  • cpukit/posix/include/rtems/posix/semaphore.h

    rd233c88 rf5c9b89  
    154154
    155155int _POSIX_Semaphore_Wait_support(
    156   sem_t              *sem,
    157   boolean             blocking,
    158   Watchdog_Interval   timeout
     156  sem_t                          *sem,
     157  Core_semaphore_Blocking_option  blocking,
     158  Watchdog_Interval               timeout
    159159);
    160160
  • cpukit/posix/inline/rtems/posix/semaphore.inl

    rd233c88 rf5c9b89  
    6565 
    6666RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get (
    67   sem_t        *id,
     67  sem_t             *id,
    6868  Objects_Locations *location
    6969)
  • cpukit/posix/src/semaphorewaitsupp.c

    rd233c88 rf5c9b89  
    2727
    2828int _POSIX_Semaphore_Wait_support(
    29   sem_t              *sem,
    30   boolean             blocking,
    31   Watchdog_Interval   timeout
     29  sem_t                          *sem,
     30  Core_semaphore_Blocking_option  blocking,
     31  Watchdog_Interval               timeout
    3232)
    3333{
    34   register POSIX_Semaphore_Control *the_semaphore;
    35   Objects_Locations                 location;
     34  POSIX_Semaphore_Control *the_semaphore;
     35  Objects_Locations        location;
    3636
    3737  the_semaphore = _POSIX_Semaphore_Get( sem, &location );
     
    6666           */
    6767          break;
     68        case CORE_SEMAPHORE_BAD_TIMEOUT_VALUE:
     69          rtems_set_errno_and_return_minus_one( EINVAL );
     70          break;
    6871      }
    6972  }
  • cpukit/posix/src/semtimedwait.c

    rd233c88 rf5c9b89  
    3636   *  The abstime is a walltime.  We turn it into an interval.
    3737   */
    38   Watchdog_Interval ticks;
    39   struct timespec   current_time;
    40   struct timespec   difference;
     38  Watchdog_Interval              ticks = 0;
     39  struct timespec                current_time;
     40  struct timespec                difference;
     41  Core_semaphore_Blocking_option blocking = CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT;
    4142
    4243  /*
    4344   *  Error check the absolute time to timeout
    4445   */
     46#if 0
    4547  if ( /* abstime->tv_sec < 0 || */ abstime->tv_nsec ) /* tv_sec is unsigned */
    46     return EINVAL;
     48    blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE;
     49  else
     50#endif
     51  if ( abstime->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
     52    blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE;
     53  else {
     54    (void) clock_gettime( CLOCK_REALTIME, &current_time );
     55    /*
     56     *  Make sure the abstime is in the future
     57     */
     58    if ( abstime->tv_sec < current_time.tv_sec )
     59      blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE;
     60    else if ( (abstime->tv_sec == current_time.tv_sec) &&
     61         (abstime->tv_nsec <= current_time.tv_nsec) )
     62      blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE;
     63    else {
     64      _POSIX_Timespec_subtract( &current_time, abstime, &difference );
     65      ticks = _POSIX_Timespec_to_interval( &difference );
     66      blocking = CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT;
     67    }
     68   }
    4769
    48   if ( abstime->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
    49     return EINVAL;
    50  
    51   (void) clock_gettime( CLOCK_REALTIME, &current_time );
    52 
    53   /*
    54    *  Make sure the abstime is in the future
    55    */
    56   if ( abstime->tv_sec < current_time.tv_sec )
    57     return EINVAL;
    58   if ( (abstime->tv_sec == current_time.tv_sec) &&
    59        (abstime->tv_nsec <= current_time.tv_nsec) )
    60     return EINVAL;
    61 
    62   _POSIX_Timespec_subtract( &current_time, abstime, &difference );
    63 
    64   ticks = _POSIX_Timespec_to_interval( &difference );
    65 
    66   return _POSIX_Semaphore_Wait_support( sem, TRUE, ticks );
     70   return _POSIX_Semaphore_Wait_support( sem, blocking, ticks );
    6771}
    68 
  • cpukit/posix/src/semwait.c

    rd233c88 rf5c9b89  
    3232)
    3333{
    34   return _POSIX_Semaphore_Wait_support( sem, TRUE, THREAD_QUEUE_WAIT_FOREVER );
     34  return _POSIX_Semaphore_Wait_support(
     35           sem,
     36           CORE_SEMAPHORE_BLOCK_FOREVER,
     37           THREAD_QUEUE_WAIT_FOREVER
     38         );
    3539}
  • cpukit/rtems/src/semobtain.c

    rd233c88 rf5c9b89  
    7272)
    7373{
    74   register Semaphore_Control *the_semaphore;
    75   Objects_Locations           location;
    76   boolean                     wait;
    77   ISR_Level                   level;
     74  register Semaphore_Control     *the_semaphore;
     75  Objects_Locations               location;
     76  ISR_Level                       level;
    7877
    7978  the_semaphore = _Semaphore_Get_interrupt_disable( id, &location, &level );
     
    9392
    9493    case OBJECTS_LOCAL:
    95       if ( _Options_Is_no_wait( option_set ) )
    96         wait = FALSE;
    97       else
    98         wait = TRUE;
    99 
    10094      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
    10195        _CORE_mutex_Seize(
    10296          &the_semaphore->Core_control.mutex,
    10397          id,
    104           wait,
     98          ((_Options_Is_no_wait( option_set )) ? FALSE : TRUE),
    10599          timeout,
    106100          level
     
    114108        &the_semaphore->Core_control.semaphore,
    115109        id,
    116         wait,
     110        ((_Options_Is_no_wait( option_set )) ?
     111          CORE_SEMAPHORE_NO_WAIT : CORE_SEMAPHORE_BLOCK_FOREVER),
    117112        timeout,
    118113        &level
  • cpukit/rtems/src/semtranslatereturncode.c

    rd233c88 rf5c9b89  
    5555 *
    5656 *  Input parameters:
    57  *    the_mutex_status - mutex status code to translate
     57 *    status - mutex status code to translate
    5858 *
    5959 *  Output parameters:
     
    7474
    7575rtems_status_code _Semaphore_Translate_core_mutex_return_code (
    76   uint32_t   the_mutex_status
     76  uint32_t   status
    7777)
    7878{
    7979#if defined(RTEMS_MULTIPROCESSING)
    80   if ( the_mutex_status == THREAD_STATUS_PROXY_BLOCKING )
     80  if ( status == THREAD_STATUS_PROXY_BLOCKING )
    8181    return RTEMS_PROXY_BLOCKING;
    82   else
    8382#endif
    84   if ( the_mutex_status > CORE_MUTEX_STATUS_CEILING_VIOLATED )
     83  if ( status > CORE_MUTEX_STATUS_CEILING_VIOLATED )
    8584    return RTEMS_INTERNAL_ERROR;
    86   else
    87     return _Semaphore_Translate_core_mutex_return_code_[the_mutex_status];
     85  return _Semaphore_Translate_core_mutex_return_code_[status];
    8886}
    8987
     
    9391 *
    9492 *  Input parameters:
    95  *    the_semaphore_status - semaphore status code to translate
     93 *    status - semaphore status code to translate
    9694 *
    9795 *  Output parameters:
     
    106104  RTEMS_TIMEOUT,            /* CORE_SEMAPHORE_TIMEOUT  */
    107105  RTEMS_INTERNAL_ERROR,     /* CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED */
    108 
     106  RTEMS_INTERNAL_ERROR      /* CORE_SEMAPHORE_BAD_TIMEOUT_VALUE */
    109107};
    110108
    111109rtems_status_code _Semaphore_Translate_core_semaphore_return_code (
    112   uint32_t   the_semaphore_status
     110  uint32_t   status
    113111)
    114112{
    115113#if defined(RTEMS_MULTIPROCESSING)
    116   if ( the_semaphore_status == THREAD_STATUS_PROXY_BLOCKING )
     114  if ( status == THREAD_STATUS_PROXY_BLOCKING )
    117115    return RTEMS_PROXY_BLOCKING;
    118   else
    119116#endif
    120   if ( the_semaphore_status > CORE_MUTEX_STATUS_CEILING_VIOLATED )
     117  if ( status > CORE_MUTEX_STATUS_CEILING_VIOLATED )
    121118    return RTEMS_INTERNAL_ERROR;
    122   else
    123     return _Semaphore_Translate_core_semaphore_return_code_[the_semaphore_status];
     119  return _Semaphore_Translate_core_semaphore_return_code_[status];
    124120}
  • cpukit/score/include/rtems/score/coresem.h

    rd233c88 rf5c9b89  
    8383   *  and this would have made its count greater than that allowed.
    8484   */
    85   CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED
     85  CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED,
     86  /** This status indicates that the semaphore was not immediately
     87   *  available and the caller passed a bad timeout value to the API
     88   *  routine.  In this case, the API required that the validity check
     89   *  for the timeout occur after the check that the semaphore was immediately
     90   *  available.
     91   */
     92  CORE_SEMAPHORE_BAD_TIMEOUT_VALUE
    8693}   CORE_semaphore_Status;
    8794
     
    117124
    118125/**
     126 *  The following enumerated type is the set of blocking options
     127 *  available to seize operation.
     128 */
     129typedef enum {
     130  /** This value indicates that the caller does not wish to block. */
     131  CORE_SEMAPHORE_NO_WAIT,
     132  /** This value indicates that the caller is willing to block forever. */
     133  CORE_SEMAPHORE_BLOCK_FOREVER,
     134  /** This value indicates that the caller is blocking with a timeout. */
     135  CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT,
     136  /** This value indicates that the caller wanted to block but passed in
     137   *  a bad timeout value to the API. Unfortunately, this is a weird case
     138   *  where the timeout bad error is required to be generated only if
     139   *  the semaphore is not available.
     140   */
     141  CORE_SEMAPHORE_BAD_TIMEOUT
     142} Core_semaphore_Blocking_option;
     143
     144/**
    119145 *  This routine initializes the semaphore based on the parameters passed.
    120146 *
     
    138164 *  @param[in] id is the Id of the API level Semaphore object associated
    139165 *         with this instance of a SuperCore Semaphore
    140  *  @param[in] wait is TRUE if the calling thread is willing to wait
     166 *  @param[in] wait is the blocking mode
    141167 *  @param[in] timeout is the number of ticks the calling thread is willing
    142168 *         to wait if @a wait is TRUE.
    143169 */
    144170void _CORE_semaphore_Seize(
    145   CORE_semaphore_Control  *the_semaphore,
    146   Objects_Id               id,
    147   boolean                  wait,
    148   Watchdog_Interval        timeout
     171  CORE_semaphore_Control         *the_semaphore,
     172  Objects_Id                      id,
     173  Core_semaphore_Blocking_option  wait,
     174  Watchdog_Interval               timeout
    149175);
    150176
  • cpukit/score/src/coresemseize.c

    rd233c88 rf5c9b89  
    5252
    5353void _CORE_semaphore_Seize(
    54   CORE_semaphore_Control  *the_semaphore,
    55   Objects_Id               id,
    56   boolean                  wait,
    57   Watchdog_Interval        timeout
     54  CORE_semaphore_Control         *the_semaphore,
     55  Objects_Id                      id,
     56  Core_semaphore_Blocking_option  wait,
     57  Watchdog_Interval               timeout
    5858)
    5959{
     
    7070  }
    7171
    72   if ( !wait ) {
    73     _ISR_Enable( level );
    74     executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
    75     return;
     72  switch ( wait ) {
     73    case CORE_SEMAPHORE_NO_WAIT:
     74      _ISR_Enable( level );
     75      executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
     76      return;
     77    case CORE_SEMAPHORE_BAD_TIMEOUT:
     78      executing->Wait.return_code = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE;
     79      return;
     80    case CORE_SEMAPHORE_BLOCK_FOREVER:
     81    case CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT:
     82      _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
     83      executing->Wait.queue          = &the_semaphore->Wait_queue;
     84      executing->Wait.id             = id;
     85      _ISR_Enable( level );
     86      _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
     87      break;
    7688  }
    7789
    78   _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
    79   executing->Wait.queue          = &the_semaphore->Wait_queue;
    80   executing->Wait.id             = id;
    81   _ISR_Enable( level );
    82 
    83   _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
    8490}
Note: See TracChangeset for help on using the changeset viewer.