Changeset 01f23374 in rtems


Ignore:
Timestamp:
Mar 21, 2014, 11:07:27 AM (6 years ago)
Author:
Christian Mauderer <Christian.Mauderer@…>
Branches:
4.11, master
Children:
9d9df8b
Parents:
8e133b25
git-author:
Christian Mauderer <Christian.Mauderer@…> (03/21/14 11:07:27)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/24/14 07:31:49)
Message:

posix: Prevent pthread_setspecific from returning EAGAIN.

The man-page for pthread_setspecific does not define the EAGAIN return value.
Further without this patch it was not possible to set keys that have been
already set a new value.

Add test for setting a new value to a already set key.

Files:
4 edited

Legend:

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

    r8e133b25 r01f23374  
    3838  Objects_Locations            location;
    3939  POSIX_Keys_Key_value_pair   *value_pair_ptr;
     40  RBTree_Node                 *p;
     41  POSIX_Keys_Key_value_pair    search_node;
    4042
    4143  the_key = _POSIX_Keys_Get( key, &location );
     
    4345
    4446    case OBJECTS_LOCAL:
    45       value_pair_ptr = _POSIX_Keys_Key_value_pair_allocate();
     47      search_node.key = key;
     48      search_node.thread_id = _Thread_Executing->Object.id;
     49      p = _RBTree_Find( &_POSIX_Keys_Key_value_lookup_tree,
     50                                    &search_node.Key_value_lookup_node );
    4651
    47       if ( !value_pair_ptr ) {
    48         _Objects_Put( &the_key->Object );
     52      if ( p ) {
     53        value_pair_ptr = _RBTree_Container_of( p,
     54                                          POSIX_Keys_Key_value_pair,
     55                                          Key_value_lookup_node );
    4956
    50         return ENOMEM;
     57        value_pair_ptr->value = value;
     58      } else {
     59        value_pair_ptr = _POSIX_Keys_Key_value_pair_allocate();
     60
     61        if ( !value_pair_ptr ) {
     62          _Objects_Put( &the_key->Object );
     63
     64          return ENOMEM;
     65        }
     66
     67        value_pair_ptr->key = key;
     68        value_pair_ptr->thread_id = _Thread_Executing->Object.id;
     69        value_pair_ptr->value = value;
     70        /* The insert can only go wrong if the same node is already in a unique
     71         * tree. This has been already checked with the _RBTree_Find() */
     72        (void) _RBTree_Insert( &_POSIX_Keys_Key_value_lookup_tree,
     73                             &(value_pair_ptr->Key_value_lookup_node) );
     74
     75        /** append rb_node to the thread API extension's chain */
     76        _Chain_Append_unprotected(
     77          &_Thread_Executing->Key_Chain,
     78          &value_pair_ptr->Key_values_per_thread_node
     79        );
    5180      }
    52 
    53       value_pair_ptr->key = key;
    54       value_pair_ptr->thread_id = _Thread_Executing->Object.id;
    55       value_pair_ptr->value = value;
    56       if ( _RBTree_Insert( &_POSIX_Keys_Key_value_lookup_tree,
    57                            &(value_pair_ptr->Key_value_lookup_node) ) ) {
    58         _Freechain_Put( (Freechain_Control *)&_POSIX_Keys_Keypool,
    59                         (void *) value_pair_ptr );
    60         _Objects_Put( &the_key->Object );
    61 
    62         return EAGAIN;
    63       }
    64 
    65       /** append rb_node to the thread API extension's chain */
    66       _Chain_Append_unprotected(
    67         &_Thread_Executing->Key_Chain,
    68         &value_pair_ptr->Key_values_per_thread_node
    69       );
    7081
    7182      _Objects_Put( &the_key->Object );
  • testsuites/psxtests/psxkey05/init.c

    r8e133b25 r01f23374  
    5353  rtems_test_assert( *value == Data_array[1] );
    5454
     55  puts( "Init - key1 pthread_setspecific - OK" );
     56  sc = pthread_setspecific( key1, &Data_array[1] );
     57  rtems_test_assert( !sc );
     58
     59  puts( "Init - key1 pthread_getspecific - OK" );
     60  value = pthread_getspecific( key1 );
     61  rtems_test_assert( *value == Data_array[1] );
     62
    5563  puts( "Init - pthread key1 delete - OK" );
    5664  sc = pthread_key_delete( key1 );
  • testsuites/psxtests/psxkey05/psxkey05.scn

    r8e133b25 r01f23374  
    99Init - key1 pthread_getspecific - OK
    1010Init - key2 pthread_getspecific - OK
     11Init - key1 pthread_setspecific - OK
     12Init - key1 pthread_getspecific - OK
    1113Init - pthread key1 delete - OK
    1214Init - pthread key2 delete - OK
Note: See TracChangeset for help on using the changeset viewer.