Changeset e600b886 in rtems


Ignore:
Timestamp:
Aug 9, 2010, 8:13:47 AM (9 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.10
Children:
54087bc
Parents:
718a0c5f
Message:

2010-08-09 Sebastian Huber <sebastian.huber@…>

PR 1615/cpukit

  • posix/src/keyrundestructors.c: Improved POSIX compliance. Now we may have an unlimited number of iterations.
Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r718a0c5f re600b886  
     12010-08-09      Sebastian Huber <sebastian.huber@embedded-brains.de>
     2
     3        PR 1615/cpukit
     4        * posix/src/keyrundestructors.c: Improved POSIX compliance.  Now we may
     5        have an unlimited number of iterations.
     6
    172010-08-09      Sebastian Huber <sebastian.huber@embedded-brains.de>
    28
  • cpukit/posix/src/keyrundestructors.c

    r718a0c5f re600b886  
    11/*
     2 *  Copyright (c) 2010 embedded brains GmbH.
     3 *
    24 *  COPYRIGHT (c) 1989-2007.
    35 *  On-Line Applications Research Corporation (OAR).
     
    1416#endif
    1517
    16 #include <errno.h>
    17 #include <limits.h>
    18 #include <pthread.h>
    19 #include <string.h>
    20 
    2118#include <rtems/system.h>
     19#include <rtems/score/object.h>
    2220#include <rtems/score/thread.h>
    23 #include <rtems/score/wkspace.h>
    2421#include <rtems/posix/key.h>
    2522
     
    3835)
    3936{
    40   uint32_t             index;
    41   uint32_t             thread_index;
    42   uint32_t             thread_api;
    43   uint32_t             iterations;
    44   bool                 are_all_null;
    45   POSIX_Keys_Control  *the_key;
    46   void                *value;
     37  Objects_Maximum thread_index = _Objects_Get_index( thread->Object.id );
     38  Objects_APIs thread_api = _Objects_Get_API( thread->Object.id );
     39  bool done = false;
    4740
    48   thread_index = _Objects_Get_index( thread->Object.id );
    49   thread_api   = _Objects_Get_API( thread->Object.id );
     41  /*
     42   *  The standard allows one to avoid a potential infinite loop and limit the
     43   *  number of iterations.  An infinite loop may happen if destructors set
     44   *  thread specific data.  This can be considered dubious.
     45   *
     46   *  Reference: 17.1.1.2 P1003.1c/Draft 10, p. 163, line 99.
     47   */
     48  while ( !done ) {
     49    Objects_Maximum index = 0;
     50    Objects_Maximum max = _POSIX_Keys_Information.maximum;
    5051
    51   iterations = 0;
     52    done = true;
    5253
    53   for ( ; ; ) {
     54    for ( index = 1 ; index <= max ; ++index ) {
     55      POSIX_Keys_Control *key = (POSIX_Keys_Control *)
     56        _POSIX_Keys_Information.local_table [ index ];
    5457
    55     are_all_null = true;
     58      if ( key != NULL && key->destructor != NULL ) {
     59        void *value = key->Values [ thread_api ][ thread_index ];
    5660
    57     for ( index=1 ; index <= _POSIX_Keys_Information.maximum ; index++ ) {
    58 
    59       the_key = (POSIX_Keys_Control *)
    60         _POSIX_Keys_Information.local_table[ index ];
    61 
    62       if ( !the_key )
    63         continue;
    64       if ( !the_key->destructor )
    65         continue;
    66 
    67       value = the_key->Values[ thread_api ][ thread_index ];
    68       if ( value ) {
    69         (*the_key->destructor)( value );
    70         if ( the_key->Values[ thread_api ][ thread_index ] )
    71           are_all_null = false;
     61        if ( value != NULL ) {
     62          key->Values [ thread_api ][ thread_index ] = NULL;
     63          (*key->destructor)( value );
     64          done = false;
     65        }
    7266      }
    7367    }
    74 
    75     if ( are_all_null == true )
    76       return;
    77 
    78     iterations++;
    79 
    80     /*
    81      *  The standard allows one to not do this and thus go into an infinite
    82      *  loop.  It seems rude to unnecessarily lock up a system.
    83      *
    84      *  Reference: 17.1.1.2 P1003.1c/Draft 10, p. 163, line 99.
    85      */
    86 
    87     if ( iterations >= PTHREAD_DESTRUCTOR_ITERATIONS )
    88       return;
    8968  }
    9069}
Note: See TracChangeset for help on using the changeset viewer.