Changeset cef5675 in rtems


Ignore:
Timestamp:
Dec 14, 2015, 10:47:47 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
f4fee477
Parents:
ef1a985
git-author:
Sebastian Huber <sebastian.huber@…> (12/14/15 10:47:47)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/03/16 09:00:54)
Message:

Optional POSIX Cleanup initialization

Update #2408.

Files:
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/Makefile.am

    ref1a985 rcef5675  
    7979
    8080## CANCEL_C_FILES
    81 libposix_a_SOURCES += src/cancel.c src/canceleval.c src/cancelrun.c \
    82     src/cleanuppop.c src/cleanuppush.c src/setcancelstate.c \
     81libposix_a_SOURCES += src/cancel.c src/canceleval.c \
     82    src/cleanuppush.c src/setcancelstate.c \
    8383    src/setcanceltype.c src/testcancel.c
    8484
  • cpukit/posix/include/rtems/posix/cancel.h

    ref1a985 rcef5675  
    2323
    2424/**
    25  * @brief POSIX run thread cancelation.
    26  *
    27  * This support routine runs through the chain of cancel handlers that
    28  * have been registered and executes them.
    29  *
    30  * @param[in] the_thread is a pointer to the thread whose cancelation handlers
    31  *            should be run
    32  */
    33 void _POSIX_Threads_cancel_run(
    34   Thread_Control *the_thread
    35 );
    36 
    37 /**
    3825 * @brief POSIX evaluate thread cancelation and enable dispatch.
    3926 *
  • cpukit/posix/include/rtems/posix/threadsup.h

    ref1a985 rcef5675  
    8686  /** This indicates if a cancelation has been requested. */
    8787  int                     cancelation_requested;
    88   /**
    89    * @brief LIFO list of cleanup contexts.
    90    */
    91   struct _pthread_cleanup_context *last_cleanup_context;
    9288} POSIX_API_Control;
    9389
  • cpukit/posix/src/cleanuppush.c

    ref1a985 rcef5675  
    22 * @file
    33 *
    4  * @brief Establishing Cancellation Handlers
     4 * @brief POSIX Cleanup Support
    55 * @ingroup POSIXAPI
    66 */
     
    2121#include <pthread.h>
    2222
     23#include <rtems/sysinit.h>
    2324#include <rtems/score/thread.h>
    2425#include <rtems/score/threaddispatch.h>
    25 #include <rtems/posix/threadsup.h>
     26#include <rtems/score/userextimpl.h>
    2627
    2728void _pthread_cleanup_push(
     
    3132)
    3233{
    33   POSIX_API_Control *thread_support;
     34  Per_CPU_Control *cpu_self;
     35  Thread_Control  *executing;
    3436
    3537  context->_routine = routine;
     
    3941  context->_canceltype = -1;
    4042
    41   _Thread_Disable_dispatch();
     43  cpu_self = _Thread_Dispatch_disable();
    4244
    43   thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
    44   context->_previous = thread_support->last_cleanup_context;
    45   thread_support->last_cleanup_context = context;
     45  executing = _Per_CPU_Get_executing( cpu_self );
     46  context->_previous = executing->last_cleanup_context;
     47  executing->last_cleanup_context = context;
    4648
    47   _Thread_Enable_dispatch();
     49  _Thread_Dispatch_enable( cpu_self );
    4850}
     51
     52void _pthread_cleanup_pop(
     53  struct _pthread_cleanup_context *context,
     54  int                              execute
     55)
     56{
     57  Per_CPU_Control *cpu_self;
     58  Thread_Control  *executing;
     59
     60  if ( execute != 0 ) {
     61    ( *context->_routine )( context->_arg );
     62  }
     63
     64  cpu_self = _Thread_Dispatch_disable();
     65
     66  executing = _Per_CPU_Get_executing( cpu_self );
     67  executing->last_cleanup_context = context->_previous;
     68
     69  _Thread_Dispatch_enable( cpu_self );
     70}
     71
     72static void _POSIX_Cleanup_terminate_extension( Thread_Control *the_thread )
     73{
     74  struct _pthread_cleanup_context *context;
     75
     76  context = the_thread->last_cleanup_context;
     77  the_thread->last_cleanup_context = NULL;
     78
     79  while ( context != NULL ) {
     80    ( *context->_routine )( context->_arg );
     81
     82    context = context->_previous;
     83  }
     84}
     85
     86static void _POSIX_Cleanup_restart_extension(
     87  Thread_Control *executing,
     88  Thread_Control *the_thread
     89)
     90{
     91  (void) executing;
     92  _POSIX_Cleanup_terminate_extension( the_thread );
     93}
     94
     95static User_extensions_Control _POSIX_Cleanup_extensions = {
     96  .Callouts = {
     97    .thread_restart = _POSIX_Cleanup_restart_extension,
     98    .thread_terminate = _POSIX_Cleanup_terminate_extension
     99  }
     100};
     101
     102static void _POSIX_Cleanup_initialization( void )
     103{
     104  _User_extensions_Add_API_set( &_POSIX_Cleanup_extensions );
     105}
     106
     107RTEMS_SYSINIT_ITEM(
     108  _POSIX_Cleanup_initialization,
     109  RTEMS_SYSINIT_POSIX_CLEANUP,
     110  RTEMS_SYSINIT_ORDER_MIDDLE
     111);
  • cpukit/posix/src/pthread.c

    ref1a985 rcef5675  
    241241}
    242242
    243 static void _POSIX_Threads_Restart_extension(
    244   Thread_Control *executing,
    245   Thread_Control *restarted
    246 )
    247 {
    248   (void) executing;
    249   _POSIX_Threads_cancel_run( restarted );
    250 }
    251 
    252243static void _POSIX_Threads_Terminate_extension(
    253244  Thread_Control *executing
     
    259250
    260251  api = executing->API_Extensions[ THREAD_API_POSIX ];
    261 
    262   /*
    263    *  Run the POSIX cancellation handlers
    264    */
    265   _POSIX_Threads_cancel_run( executing );
    266252
    267253  _Thread_Disable_dispatch();
     
    327313  { _POSIX_Threads_Create_extension,          /* create */
    328314    NULL,                                     /* start */
    329     _POSIX_Threads_Restart_extension,         /* restart */
     315    NULL,                                     /* restart */
    330316    NULL,                                     /* delete */
    331317    NULL,                                     /* switch */
  • cpukit/score/include/rtems/score/percpu.h

    ref1a985 rcef5675  
    517517}
    518518
     519static inline struct _Thread_Control *_Per_CPU_Get_executing(
     520  const Per_CPU_Control *cpu
     521)
     522{
     523  return cpu->executing;
     524}
     525
    519526static inline bool _Per_CPU_Is_processor_started(
    520527  const Per_CPU_Control *cpu
  • cpukit/score/include/rtems/score/thread.h

    ref1a985 rcef5675  
    3939  #include <rtems/score/cpuset.h>
    4040#endif
     41
     42struct _pthread_cleanup_context;
    4143
    4244struct Per_CPU_Control;
     
    852854
    853855  /**
     856   * @brief LIFO list of POSIX cleanup contexts.
     857   */
     858  struct _pthread_cleanup_context *last_cleanup_context;
     859
     860  /**
    854861   * @brief Variable length array of user extension pointers.
    855862   *
  • cpukit/score/include/rtems/sysinit.h

    ref1a985 rcef5675  
    4545#define RTEMS_SYSINIT_POSIX_SIGNALS              000360
    4646#define RTEMS_SYSINIT_POSIX_THREADS              000361
     47#define RTEMS_SYSINIT_POSIX_CLEANUP              00036a
    4748#define RTEMS_SYSINIT_IDLE_THREADS               000380
    4849#define RTEMS_SYSINIT_BSP_LIBC                   000400
  • testsuites/sptests/spsysinit01/init.c

    ref1a985 rcef5675  
    1818
    1919#include <assert.h>
     20#include <pthread.h>
    2021#include <string.h>
    2122#include <stdlib.h>
     
    4142#include <rtems/rtems/timerimpl.h>
    4243#include <rtems/score/apimutex.h>
     44#include <rtems/score/chainimpl.h>
    4345#include <rtems/score/sysstate.h>
    4446#include <rtems/score/userextimpl.h>
     
    8587  POSIX_THREADS_PRE,
    8688  POSIX_THREADS_POST,
     89  POSIX_CLEANUP_PRE,
     90  POSIX_CLEANUP_POST,
    8791#endif /* RTEMS_POSIX_API */
    8892  IDLE_THREADS_PRE,
     
    359363}
    360364
     365static size_t user_extensions_pre_posix_cleanup;
     366
     367FIRST(RTEMS_SYSINIT_POSIX_CLEANUP)
     368{
     369  user_extensions_pre_posix_cleanup =
     370    _Chain_Node_count_unprotected(&_User_extensions_List);
     371  next_step(POSIX_CLEANUP_PRE);
     372}
     373
     374LAST(RTEMS_SYSINIT_POSIX_CLEANUP)
     375{
     376  assert(
     377    user_extensions_pre_posix_cleanup + 1 ==
     378      _Chain_Node_count_unprotected(&_User_extensions_List)
     379  );
     380  next_step(POSIX_CLEANUP_POST);
     381}
     382
    361383#endif /* RTEMS_POSIX_API */
    362384
     
    436458static void Init(rtems_task_argument arg)
    437459{
     460#ifdef RTEMS_POSIX_API
     461  pthread_cleanup_push(NULL, NULL);
     462  pthread_cleanup_pop(0);
     463#endif /* RTEMS_POSIX_API */
    438464  next_step(INIT_TASK);
    439465  rtems_test_endk();
Note: See TracChangeset for help on using the changeset viewer.