Changeset 927a0a1 in rtems


Ignore:
Timestamp:
Dec 2, 2013, 7:33:35 AM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
aaaedba
Parents:
8abf006
git-author:
Sebastian Huber <sebastian.huber@…> (12/02/13 07:33:35)
git-committer:
Sebastian Huber <sebastian.huber@…> (12/02/13 08:24:51)
Message:

posix: Use cleanup contexts on the stack

Provide support for latest Newlib <pthread.h> change. The cleanup
contexts are stored on the thread stack. This is conformant with the
POSIX requirements for the pthread_cleanup_push() and
pthread_cleanup_pop() statement pair.

Passing an invalid pointer as the routine to pthread_cleanup_push() is
now a usage error and the behaviour is undefined.

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/configure.ac

    r8abf006 r927a0a1  
    141141  AC_CHECK_TYPES([pthread_barrier_t])
    142142  AC_CHECK_TYPES([pthread_spinlock_t])
     143  AC_CHECK_TYPES([struct _pthread_cleanup_context],[],[],[#include <pthread.h>])
    143144])
    144145
  • cpukit/posix/include/rtems/posix/cancel.h

    r8abf006 r927a0a1  
    2222#include <rtems/posix/threadsup.h>
    2323
     24#ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
    2425/**
    2526 * This structure is used to manage the cancelation handlers.
     
    3334  void       *arg;
    3435}  POSIX_Cancel_Handler_control;
     36#endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    3537
    3638/**
  • cpukit/posix/include/rtems/posix/threadsup.h

    r8abf006 r927a0a1  
    8181  /** This indicates if a cancelation has been requested. */
    8282  int                     cancelation_requested;
     83#ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
    8384  /** This is the set of cancelation handlers. */
    8485  Chain_Control           Cancellation_Handlers;
     86#else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
     87  /**
     88   * @brief LIFO list of cleanup contexts.
     89   */
     90  struct _pthread_cleanup_context *last_cleanup_context;
     91#endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    8592
    8693  /**
  • cpukit/posix/src/cancelrun.c

    r8abf006 r927a0a1  
    2020
    2121#include <pthread.h>
    22 #include <errno.h>
    2322
    24 #include <rtems/system.h>
     23#include <rtems/score/thread.h>
     24#include <rtems/score/threaddispatch.h>
     25#include <rtems/posix/cancel.h>
     26#include <rtems/posix/threadsup.h>
     27
     28#ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
     29
    2530#include <rtems/score/chainimpl.h>
    2631#include <rtems/score/isr.h>
    27 #include <rtems/score/thread.h>
    2832#include <rtems/score/wkspace.h>
    29 #include <rtems/posix/cancel.h>
    3033#include <rtems/posix/pthreadimpl.h>
    31 #include <rtems/posix/threadsup.h>
    3234
    3335void _POSIX_Threads_cancel_run(
     
    5860  }
    5961}
     62
     63#else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
     64
     65void _POSIX_Threads_cancel_run(
     66  Thread_Control *the_thread
     67)
     68{
     69  struct _pthread_cleanup_context *context;
     70  POSIX_API_Control               *thread_support;
     71
     72  _Thread_Disable_dispatch();
     73
     74  thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
     75  thread_support->cancelability_state = PTHREAD_CANCEL_DISABLE;
     76
     77  context = thread_support->last_cleanup_context;
     78  thread_support->last_cleanup_context = NULL;
     79
     80  _Thread_Enable_dispatch();
     81
     82  while ( context != NULL ) {
     83    ( *context->_routine )( context->_arg );
     84
     85    context = context->_previous;
     86  }
     87}
     88
     89#endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
  • cpukit/posix/src/cleanuppop.c

    r8abf006 r927a0a1  
    2020
    2121#include <pthread.h>
    22 #include <errno.h>
    2322
    24 #include <rtems/system.h>
     23#include <rtems/score/thread.h>
     24#include <rtems/score/threaddispatch.h>
     25#include <rtems/posix/threadsup.h>
     26
     27#ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
     28
    2529#include <rtems/score/chainimpl.h>
    2630#include <rtems/score/isr.h>
    27 #include <rtems/score/thread.h>
    2831#include <rtems/score/wkspace.h>
    2932#include <rtems/posix/cancel.h>
    3033#include <rtems/posix/pthreadimpl.h>
    31 #include <rtems/posix/threadsup.h>
    3234
    3335/*
     
    8082    (*tmp_handler.routine)( tmp_handler.arg );
    8183}
     84
     85#else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
     86
     87void _pthread_cleanup_pop(
     88  struct _pthread_cleanup_context *context,
     89  int                              execute
     90)
     91{
     92  POSIX_API_Control *thread_support;
     93
     94  if ( execute != 0 ) {
     95    ( *context->_routine )( context->_arg );
     96  }
     97
     98  _Thread_Disable_dispatch();
     99
     100  thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
     101  thread_support->last_cleanup_context = context->_previous;
     102
     103  _Thread_Enable_dispatch();
     104}
     105
     106#endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
  • cpukit/posix/src/cleanuppush.c

    r8abf006 r927a0a1  
    2020
    2121#include <pthread.h>
    22 #include <errno.h>
    2322
    24 #include <rtems/system.h>
     23#include <rtems/score/thread.h>
     24#include <rtems/score/threaddispatch.h>
     25#include <rtems/posix/threadsup.h>
     26
     27#ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
     28
    2529#include <rtems/score/chainimpl.h>
    2630#include <rtems/score/isr.h>
    27 #include <rtems/score/thread.h>
    2831#include <rtems/score/wkspace.h>
    2932#include <rtems/posix/cancel.h>
    3033#include <rtems/posix/pthreadimpl.h>
    31 #include <rtems/posix/threadsup.h>
    3234
    3335/*
     
    6769  _Thread_Enable_dispatch();
    6870}
     71
     72#else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
     73
     74void _pthread_cleanup_push(
     75  struct _pthread_cleanup_context   *context,
     76  void                            ( *routine )( void * ),
     77  void                              *arg
     78)
     79{
     80  POSIX_API_Control *thread_support;
     81
     82  context->_routine = routine;
     83  context->_arg = arg;
     84
     85  /* This value is unused, just provide a deterministic value */
     86  context->_canceltype = -1;
     87
     88  _Thread_Disable_dispatch();
     89
     90  thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
     91  context->_previous = thread_support->last_cleanup_context;
     92  thread_support->last_cleanup_context = context;
     93
     94  _Thread_Enable_dispatch();
     95}
     96
     97#endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
  • cpukit/posix/src/pthread.c

    r8abf006 r927a0a1  
    201201  api->cancelability_state = PTHREAD_CANCEL_ENABLE;
    202202  api->cancelability_type = PTHREAD_CANCEL_DEFERRED;
     203#ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
    203204  _Chain_Initialize_empty (&api->Cancellation_Handlers);
     205#else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
     206  api->last_cleanup_context = NULL;
     207#endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    204208
    205209  /*
  • testsuites/psxtests/psxcleanup/psxcleanup.c

    r8abf006 r927a0a1  
    251251  sleep(1);
    252252
    253   /*************** ERROR CASES  ***************/
    254   puts("Call pthread_cleanup_push with NULL handler");
    255   pthread_cleanup_push(NULL, NULL);
    256 
    257   puts("Call pthread_cleanup_pop with no push");
    258   pthread_cleanup_pop(1);
    259 
    260253  /*************** END OF TEST *****************/
    261254  puts( "*** END OF POSIX CLEANUP TEST ***\n" );
Note: See TracChangeset for help on using the changeset viewer.