Changeset 6efa349 in rtems


Ignore:
Timestamp:
Apr 14, 2016, 6:56:53 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
8228548
Parents:
a12724f9
Message:

posix: Run key destructors during thread restart

POSIX key destructors must be called during thread restart. Just like
the POSIX cleanup handlers. This ensures that the TLS object
destructors are called during thread restart for example. It is
important for the global construction, which uses a thread restart to
run the Init task in a clean environment.

Close #2689.

Files:
5 edited

Legend:

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

    ra12724f9 r6efa349  
    112112}
    113113
     114static void _POSIX_Keys_Restart_run_destructors(
     115  Thread_Control *executing,
     116  Thread_Control *the_thread
     117)
     118{
     119  (void) executing;
     120  _POSIX_Keys_Run_destructors( the_thread );
     121}
     122
    114123static User_extensions_Control _POSIX_Keys_Extensions = {
    115124  .Callouts = {
     125    .thread_restart = _POSIX_Keys_Restart_run_destructors,
    116126    .thread_terminate = _POSIX_Keys_Run_destructors
    117127  }
  • testsuites/psxtests/psxkey06/init.c

    ra12724f9 r6efa349  
    2020const char rtems_test_name[] = "PSXKEY 6";
    2121
    22 /* forward declarations to avoid warnings */
    23 rtems_task Init(rtems_task_argument argument);
    24 rtems_task Test_Thread1(rtems_task_argument argument);
    25 rtems_task Test_Thread2(rtems_task_argument argument);
    26 
    27 int Data_array[4] = {1, 2, 3, 4};
    28 
    29 pthread_key_t key1, key2;
    30 
    31 rtems_task Test_Thread1( rtems_task_argument argument )
     22static int Data_array[4] = {1, 2, 3, 4};
     23
     24static pthread_key_t key1, key2, key3;
     25
     26static rtems_id Thread_Master;
     27
     28static int Key3_Destructor_Counter;
     29
     30static void Wake_Up_Master(void)
     31{
     32  rtems_status_code rc;
     33
     34  rc = rtems_event_transient_send( Thread_Master );
     35  rtems_test_assert( rc == RTEMS_SUCCESSFUL );
     36}
     37
     38static void Wait_For_Worker(void)
     39{
     40  rtems_status_code rc;
     41
     42  rc = rtems_event_transient_receive(
     43    RTEMS_WAIT,
     44    RTEMS_NO_TIMEOUT
     45  );
     46  rtems_test_assert( rc == RTEMS_SUCCESSFUL );
     47}
     48
     49static rtems_task Test_Thread1( rtems_task_argument argument )
    3250{
    3351  int sc;
     
    6078}
    6179
    62 rtems_task Test_Thread2( rtems_task_argument argument )
     80static rtems_task Test_Thread2( rtems_task_argument argument )
    6381{
    6482  int sc;
     
    84102}
    85103
    86 rtems_task Init( rtems_task_argument ignored )
     104static void Key3_Destructor( void *value )
     105{
     106  rtems_test_assert( value == &Thread_Master );
     107  ++Key3_Destructor_Counter;
     108}
     109
     110static rtems_task Test_Thread3( rtems_task_argument argument )
     111{
     112  int   sc;
     113  void *value;
     114
     115  puts( "Test_Thread 3 - key3 pthread_getspecific - OK" );
     116  value = pthread_getspecific( key3 );
     117  rtems_test_assert( value == NULL );
     118
     119  puts( "Test_Thread 3 - key3 pthread_setspecific - OK" );
     120  sc = pthread_setspecific( key3, &Thread_Master );
     121  rtems_test_assert( sc == 0 );
     122
     123  if ( argument == 0 ) {
     124    puts( "Test_Thread 3 - restart self - OK" );
     125    rtems_task_restart( RTEMS_SELF, 1 );
     126  } else if ( argument == 1 ) {
     127    Wake_Up_Master();
     128    rtems_task_delete( RTEMS_SELF );
     129  }
     130
     131  rtems_test_assert( false );
     132}
     133
     134static rtems_task Init( rtems_task_argument ignored )
    87135{
    88136  rtems_id          thread1;
    89137  rtems_id          thread2;
     138  rtems_id          thread3;
    90139  rtems_status_code rc;
    91140  int               sc;
     
    93142
    94143  TEST_BEGIN();
     144
     145  Thread_Master = rtems_task_self();
    95146
    96147  puts( "Init - pthread key1 create - OK" );
     
    144195  rtems_test_assert( sc == 0 );
    145196
     197  puts( "Init - pthread key3 create - OK" );
     198  sc = pthread_key_create( &key3, Key3_Destructor );
     199  rtems_test_assert( sc == 0 );
     200
     201  puts( "Init - thread3 create - OK" );
     202  rc = rtems_task_create(
     203    rtems_build_name( 'R', 'E', 'S', 'T' ),
     204    1,
     205    RTEMS_MINIMUM_STACK_SIZE,
     206    RTEMS_DEFAULT_MODES,
     207    RTEMS_DEFAULT_ATTRIBUTES,
     208    &thread3
     209  );
     210  rtems_test_assert( rc == RTEMS_SUCCESSFUL );
     211
     212  puts( "Init - thread3 start - OK" );
     213  rc = rtems_task_start( thread3, Test_Thread3, 0 );
     214  rtems_test_assert( rc == RTEMS_SUCCESSFUL );
     215
     216  Wait_For_Worker();
     217
     218  rtems_test_assert( Key3_Destructor_Counter == 2 );
     219
     220  puts( "Init - pthread key3 delete - OK" );
     221  sc = pthread_key_delete( key3 );
     222  rtems_test_assert( sc == 0 );
     223
    146224  TEST_END();
    147225  rtems_test_exit(0);
  • testsuites/psxtests/psxkey06/psxkey06.scn

    ra12724f9 r6efa349  
    1 *** TEST KEY 06 ***
     1*** BEGIN OF TEST PSXKEY 6 ***
    22Init - pthread key1 create - OK
    33Init - pthread key2 create - OK
    4 Init - pthread1 create - OK
    5 Init - pthread2 create - OK
     4Init - thread1 create - OK
     5Init - thread2 create - OK
    66Init - sleep - let thread run - OK
    77Test_Thread 1 - key1 pthread_setspecific - OK
     
    1616Init - pthread key1 delete - OK
    1717Init - pthread key2 delete - OK
    18 *** END OF TEST KEY 06 ***
     18Init - pthread key3 create - OK
     19Init - thread3 create - OK
     20Init - thread3 start - OK
     21Test_Thread 3 - key3 pthread_getspecific - OK
     22Test_Thread 3 - key3 pthread_setspecific - OK
     23Test_Thread 3 - restart self - OK
     24Test_Thread 3 - key3 pthread_getspecific - OK
     25Test_Thread 3 - key3 pthread_setspecific - OK
     26Init - pthread key3 delete - OK
     27*** END OF TEST PSXKEY 6 ***
  • testsuites/sptests/sptls02/init.cc

    ra12724f9 r6efa349  
    11/*
    2  * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2014, 2016 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    163163static rtems_id masterTask;
    164164
    165 static void task(rtems_task_argument arg)
    166 {
     165static void wakeUpMaster()
     166{
     167        rtems_status_code sc = rtems_event_transient_send(masterTask);
     168        rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     169}
     170
     171static void waitForWorker()
     172{
     173        rtems_status_code sc = rtems_event_transient_receive(
     174                RTEMS_WAIT,
     175                RTEMS_NO_TIMEOUT
     176        );
     177        rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     178}
     179
     180static void worker(rtems_task_argument arg)
     181{
     182        wakeUpMaster();
    167183        checkTLSValues();
    168184
     
    183199        a3.clobber();
    184200
    185         rtems_status_code sc = rtems_event_transient_send(masterTask);
    186         rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    187 
    188         sc = rtems_task_suspend(RTEMS_SELF);
    189         rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    190 }
    191 
    192 static void testTask()
     201        wakeUpMaster();
     202
     203        (void) rtems_task_suspend(RTEMS_SELF);
     204        rtems_test_assert(false);
     205}
     206
     207static void testWorkerTask()
    193208{
    194209        checkTLSValues();
     
    197212        rtems_status_code sc = rtems_task_create(
    198213                rtems_build_name('T', 'A', 'S', 'K'),
    199                 RTEMS_MINIMUM_PRIORITY,
     214                2,
    200215                RTEMS_MINIMUM_STACK_SIZE,
    201216                RTEMS_DEFAULT_MODES,
     
    207222        const long gc = A::globalCounter();
    208223
    209         sc = rtems_task_start(id, task, gc);
    210         rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    211 
    212         sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    213         rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     224        sc = rtems_task_start(id, worker, gc);
     225        rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     226
     227        waitForWorker();
     228        rtems_test_assert(A::globalCounter() == gc);
     229
     230        waitForWorker();
     231        rtems_test_assert(A::globalCounter() == gc + 3);
     232
     233        sc = rtems_task_restart(id, gc);
     234        rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     235
     236        waitForWorker();
     237        rtems_test_assert(A::globalCounter() == gc);
     238
     239        waitForWorker();
     240        rtems_test_assert(A::globalCounter() == gc + 3);
    214241
    215242        sc = rtems_task_delete(id);
     
    233260        masterTask = rtems_task_self();
    234261
    235         testTask();
     262        testWorkerTask();
    236263
    237264        rtems_resource_snapshot snapshot;
    238265        rtems_resource_snapshot_take(&snapshot);
    239266
    240         testTask();
     267        testWorkerTask();
    241268
    242269        rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
  • testsuites/sptests/sptls02/sptls02.scn

    ra12724f9 r6efa349  
    1 *** TEST SPTLS 2 ***
     1*** BEGIN OF TEST SPTLS 2 ***
    22A::globalCounter() = 0
    33A::globalCounter() = 3
Note: See TracChangeset for help on using the changeset viewer.