Changeset 82f90743 in rtems


Ignore:
Timestamp:
May 21, 2014, 8:30:34 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
1bf0666
Parents:
c8e83288
git-author:
Sebastian Huber <sebastian.huber@…> (05/21/14 08:30:34)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/21/14 09:48:25)
Message:

score: _Thread_Set_life_protection()

Enable usage of _Thread_Set_life_protection() in thread dispatch
critical sections. This can be used to enable the thread
life-protection with thread dispatching disabled and then enable thread
dispatching.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/src/threadrestart.c

    rc8e83288 r82f90743  
    374374    _Thread_Disable_dispatch();
    375375    _Thread_Enable_dispatch();
    376 
    377     _Assert_Not_reached();
    378376  }
    379377#endif
     
    386384    _Thread_Start_life_change_for_executing( executing );
    387385    _Thread_Enable_dispatch();
    388 
    389     _Assert_Not_reached();
    390386  }
    391387
  • testsuites/smptests/smpthreadlife01/init.c

    rc8e83288 r82f90743  
    183183}
    184184
    185 static void delay_ipi_task(rtems_task_argument arg)
     185static void delay_ipi_task(rtems_task_argument variant)
    186186{
    187187  test_context *ctx = &test_instance;
     
    199199  rtems_counter_delay_nanoseconds(100000000);
    200200
    201   /* We get deleted as a side effect of enabling the thread life protection */
     201  if (variant != 0) {
     202    _Thread_Disable_dispatch();
     203  }
     204
     205  /*
     206   * We get deleted as a side effect of enabling the thread life protection or
     207   * later if we enable the thread dispatching.
     208   */
    202209  _Thread_Set_life_protection(true);
     210
     211  if (variant != 0) {
     212    _Thread_Enable_dispatch();
     213  }
     214
    203215  rtems_test_assert(0);
    204216}
    205217
    206 static void test_set_life_protection(void)
     218static void test_set_life_protection(rtems_task_argument variant)
    207219{
    208220  test_context *ctx = &test_instance;
     
    223235  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    224236
    225   sc = rtems_task_start(id, delay_ipi_task, 0);
     237  sc = rtems_task_start(id, delay_ipi_task, variant);
    226238  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    227239
     
    302314    test_restart();
    303315    test_delete();
    304     test_set_life_protection();
     316    test_set_life_protection(0);
     317    test_set_life_protection(1);
    305318    test_wait_for_execution_stop();
    306319  }
  • testsuites/sptests/spthreadlife01/init.c

    rc8e83288 r82f90743  
    1919#include <rtems.h>
    2020#include <rtems/libcsupport.h>
     21
     22#include <rtems/score/threadimpl.h>
    2123
    2224#include "tmacros.h"
     
    4951  DELETE_2,
    5052  DELETE_3,
     53  SET_PROTECTION,
     54  SET_PROTECTION_DONE,
     55  CLEAR_PROTECTION,
     56  DELETE_4,
     57  DELETE_5,
     58  DELETE_6,
    5159  INVALID
    5260} test_state;
     
    158166  assert_priority(PRIO_INIT);
    159167
    160   rtems_test_assert(ctx->current == DELETE_2);
    161   ctx->current = DELETE_3;
     168  switch (ctx->current) {
     169    case DELETE_2:
     170      ctx->current = DELETE_3;
     171      break;
     172    case DELETE_5:
     173      ctx->current = DELETE_6;
     174      break;
     175    default:
     176      rtems_test_assert(0);
     177      break;
     178  }
    162179}
    163180
     
    180197      ctx->current = DELETE_2;
    181198      break;
     199    case DELETE_4:
     200      ctx->current = DELETE_5;
     201      break;
    182202    default:
    183203      rtems_test_assert(0);
     
    193213    test_state state = ctx->current;
    194214    rtems_status_code sc;
     215    bool previous_thread_life_protection;
    195216
    196217    switch (state) {
     
    232253        assert_priority(PRIO_HIGH);
    233254        break;
     255      case SET_PROTECTION:
     256        _Thread_Disable_dispatch();
     257        previous_thread_life_protection = _Thread_Set_life_protection(true);
     258        rtems_test_assert(!previous_thread_life_protection);
     259        _Thread_Enable_dispatch();
     260        break;
     261      case CLEAR_PROTECTION:
     262        _Thread_Disable_dispatch();
     263        previous_thread_life_protection = _Thread_Set_life_protection(false);
     264        rtems_test_assert(previous_thread_life_protection);
     265        ctx->current = DELETE_4;
     266        _Thread_Enable_dispatch();
     267        break;
    234268      default:
    235269        rtems_test_assert(0);
     
    256290}
    257291
    258 static void test(void)
    259 {
    260   test_context *ctx = &test_instance;
    261   rtems_status_code sc;
    262   rtems_resource_snapshot snapshot;
    263 
    264   ctx->main_task_id = rtems_task_self();
    265 
    266   rtems_resource_snapshot_take(&snapshot);
    267 
    268   create_sema(ctx);
     292static void create_and_start_worker(test_context *ctx)
     293{
     294  rtems_status_code sc;
    269295
    270296  sc = rtems_task_create(
     
    280306  sc = rtems_task_start(ctx->worker_task_id, worker_task, 0);
    281307  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     308}
     309
     310static void test(void)
     311{
     312  test_context *ctx = &test_instance;
     313  rtems_status_code sc;
     314  rtems_resource_snapshot snapshot;
     315
     316  ctx->main_task_id = rtems_task_self();
     317
     318  rtems_resource_snapshot_take(&snapshot);
     319
     320  create_sema(ctx);
     321  create_and_start_worker(ctx);
    282322
    283323  change_state_and_wait(ctx, INIT, SET_PRIO, SET_PRIO_DONE);
     
    317357  rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
    318358
    319   rtems_test_assert(ctx->current == DELETE_3);
     359  create_and_start_worker(ctx);
     360
     361  change_state_and_wait(ctx, DELETE_3, SET_PROTECTION, SET_PROTECTION_DONE);
     362  change_state(ctx, SET_PROTECTION_DONE, CLEAR_PROTECTION, INVALID);
     363
     364  sc = rtems_task_delete(ctx->worker_task_id);
     365  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     366
     367  rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
     368
     369  rtems_test_assert(ctx->current == DELETE_6);
    320370}
    321371
Note: See TracChangeset for help on using the changeset viewer.