Changeset f6a1ef9 in rtems


Ignore:
Timestamp:
Nov 24, 2015, 2:58:26 PM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
8ce0b0cb
Parents:
d62dfc7
git-author:
Sebastian Huber <sebastian.huber@…> (11/24/15 14:58:26)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/24/15 15:00:14)
Message:

posix: Require struct _pthread_cleanup_context

This structure is available in Newlib since 2013-11-29 (Git commit
a534dfd26e765047621acd0eda656ded886e7108).

Location:
cpukit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • cpukit/configure.ac

    rd62dfc7 rf6a1ef9  
    174174  AC_CHECK_TYPES([pthread_barrier_t])
    175175  AC_CHECK_TYPES([pthread_spinlock_t])
    176   AC_CHECK_TYPES([struct _pthread_cleanup_context],[],[],[#include <pthread.h>])
     176  AC_CHECK_TYPES([struct _pthread_cleanup_context],[],[AC_MSG_ERROR([struct _pthread_cleanup_context in <pthread.h> is mandatory])],[#include <pthread.h>])
    177177])
    178178
  • cpukit/posix/include/rtems/posix/cancel.h

    rd62dfc7 rf6a1ef9  
    2121
    2222#include <rtems/posix/threadsup.h>
    23 
    24 #ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
    25 /**
    26  * This structure is used to manage the cancelation handlers.
    27  */
    28 typedef struct {
    29   /** This field is the Chain Node so we can put these on lists. */
    30   Chain_Node  Node;
    31   /** This field is the cancelation routine. */
    32   void      (*routine)( void * );
    33   /** This field is the argument to the cancelation routine. */
    34   void       *arg;
    35 }  POSIX_Cancel_Handler_control;
    36 #endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    3723
    3824/**
  • cpukit/posix/include/rtems/posix/threadsup.h

    rd62dfc7 rf6a1ef9  
    8686  /** This indicates if a cancelation has been requested. */
    8787  int                     cancelation_requested;
    88 #ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
    89   /** This is the set of cancelation handlers. */
    90   Chain_Control           Cancellation_Handlers;
    91 #else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    9288  /**
    9389   * @brief LIFO list of cleanup contexts.
    9490   */
    9591  struct _pthread_cleanup_context *last_cleanup_context;
    96 #endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    97 
    9892} POSIX_API_Control;
    9993
  • cpukit/posix/src/cancelrun.c

    rd62dfc7 rf6a1ef9  
    2626#include <rtems/posix/threadsup.h>
    2727
    28 #ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
    29 
    30 #include <rtems/score/chainimpl.h>
    31 #include <rtems/score/isr.h>
    32 #include <rtems/score/wkspace.h>
    33 #include <rtems/posix/pthreadimpl.h>
    34 
    35 void _POSIX_Threads_cancel_run(
    36   Thread_Control *the_thread
    37 )
    38 {
    39   POSIX_Cancel_Handler_control      *handler;
    40   Chain_Control                     *handler_stack;
    41   POSIX_API_Control                 *thread_support;
    42   ISR_Level                          level;
    43 
    44   thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
    45 
    46   handler_stack = &thread_support->Cancellation_Handlers;
    47 
    48   thread_support->cancelability_state = PTHREAD_CANCEL_DISABLE;
    49 
    50   while ( !_Chain_Is_empty( handler_stack ) ) {
    51     _ISR_Disable( level );
    52       handler = (POSIX_Cancel_Handler_control *)
    53            _Chain_Tail( handler_stack )->previous;
    54       _Chain_Extract_unprotected( &handler->Node );
    55     _ISR_Enable( level );
    56 
    57     (*handler->routine)( handler->arg );
    58 
    59     _Workspace_Free( handler );
    60   }
    61 }
    62 
    63 #else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    64 
    6528void _POSIX_Threads_cancel_run(
    6629  Thread_Control *the_thread
     
    8649  }
    8750}
    88 
    89 #endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
  • cpukit/posix/src/cleanuppop.c

    rd62dfc7 rf6a1ef9  
    2525#include <rtems/posix/threadsup.h>
    2626
    27 #ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
    28 
    29 #include <rtems/score/chainimpl.h>
    30 #include <rtems/score/isr.h>
    31 #include <rtems/score/wkspace.h>
    32 #include <rtems/posix/cancel.h>
    33 #include <rtems/posix/pthreadimpl.h>
    34 
    35 /*
    36  *  18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
    37  */
    38 
    39 void pthread_cleanup_pop(
    40   int    execute
    41 )
    42 {
    43   POSIX_Cancel_Handler_control      *handler;
    44   POSIX_Cancel_Handler_control      tmp_handler;
    45   Chain_Control                     *handler_stack;
    46   POSIX_API_Control                 *thread_support;
    47   ISR_Level                          level;
    48 
    49   thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
    50 
    51   handler_stack = &thread_support->Cancellation_Handlers;
    52 
    53   /*
    54    * We need interrupts disabled to safely check the chain and pull
    55    * the last element off.  But we also need dispatching disabled to
    56    * ensure that we do not get prempted and deleted while we are holding
    57    * memory that needs to be freed.
    58    */
    59 
    60   _Thread_Disable_dispatch();
    61   _ISR_Disable( level );
    62 
    63     if ( _Chain_Is_empty( handler_stack ) ) {
    64       _Thread_Enable_dispatch();
    65       _ISR_Enable( level );
    66       return;
    67     }
    68 
    69     handler = (POSIX_Cancel_Handler_control *)
    70         _Chain_Tail( handler_stack )->previous;
    71     _Chain_Extract_unprotected( &handler->Node );
    72 
    73   _ISR_Enable( level );
    74 
    75   tmp_handler = *handler;
    76 
    77   _Workspace_Free( handler );
    78 
    79   _Thread_Enable_dispatch();
    80 
    81   if ( execute )
    82     (*tmp_handler.routine)( tmp_handler.arg );
    83 }
    84 
    85 #else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    86 
    8727void _pthread_cleanup_pop(
    8828  struct _pthread_cleanup_context *context,
     
    10343  _Thread_Enable_dispatch();
    10444}
    105 
    106 #endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
  • cpukit/posix/src/cleanuppush.c

    rd62dfc7 rf6a1ef9  
    2525#include <rtems/posix/threadsup.h>
    2626
    27 #ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
    28 
    29 #include <rtems/score/chainimpl.h>
    30 #include <rtems/score/isr.h>
    31 #include <rtems/score/wkspace.h>
    32 #include <rtems/posix/cancel.h>
    33 #include <rtems/posix/pthreadimpl.h>
    34 
    35 /*
    36  *  18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
    37  */
    38 
    39 void pthread_cleanup_push(
    40   void   (*routine)( void * ),
    41   void    *arg
    42 )
    43 {
    44   POSIX_Cancel_Handler_control      *handler;
    45   Chain_Control                     *handler_stack;
    46   POSIX_API_Control                 *thread_support;
    47 
    48   /*
    49    *  The POSIX standard does not address what to do when the routine
    50    *  is NULL.  It also does not address what happens when we cannot
    51    *  allocate memory or anything else bad happens.
    52    */
    53   if ( !routine )
    54     return;
    55 
    56   _Thread_Disable_dispatch();
    57   handler = _Workspace_Allocate( sizeof( POSIX_Cancel_Handler_control ) );
    58 
    59   if ( handler ) {
    60     thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
    61 
    62     handler_stack = &thread_support->Cancellation_Handlers;
    63 
    64     handler->routine = routine;
    65     handler->arg = arg;
    66 
    67     _Chain_Append( handler_stack, &handler->Node );
    68   }
    69   _Thread_Enable_dispatch();
    70 }
    71 
    72 #else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    73 
    7427void _pthread_cleanup_push(
    7528  struct _pthread_cleanup_context   *context,
     
    9447  _Thread_Enable_dispatch();
    9548}
    96 
    97 #endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
  • cpukit/posix/src/pthread.c

    rd62dfc7 rf6a1ef9  
    210210  api->cancelability_state = PTHREAD_CANCEL_ENABLE;
    211211  api->cancelability_type = PTHREAD_CANCEL_DEFERRED;
    212 #ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
    213   _Chain_Initialize_empty (&api->Cancellation_Handlers);
    214 #else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    215212  api->last_cleanup_context = NULL;
    216 #endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    217213
    218214  /*
Note: See TracChangeset for help on using the changeset viewer.