Changeset 345fc11 in rtems


Ignore:
Timestamp:
May 22, 2008, 8:38:03 PM (12 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.9, master
Children:
4ac1d23
Parents:
cdc8309
Message:

2008-05-22 Joel Sherrill <joel.sherrill@…>

  • itron/include/rtems/itron/task.h, itron/src/del_tsk.c, itron/src/exd_tsk.c, itron/src/task.c, posix/include/rtems/posix/threadsup.h, posix/src/cancel.c, posix/src/cancelrun.c, posix/src/pthread.c, posix/src/pthreadexit.c, posix/src/setcancelstate.c, posix/src/setcanceltype.c, posix/src/testcancel.c, rtems/src/taskdelete.c, score/inline/rtems/score/object.inl, score/src/objectclose.c, score/src/threadclose.c: Make all task delete/exit/cancel routines follow the same critical section pattern. Also ensure that POSIX cancelation routines are run at thread exit.
Location:
cpukit
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rcdc8309 r345fc11  
     12008-05-22      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * itron/include/rtems/itron/task.h, itron/src/del_tsk.c,
     4        itron/src/exd_tsk.c, itron/src/task.c,
     5        posix/include/rtems/posix/threadsup.h, posix/src/cancel.c,
     6        posix/src/cancelrun.c, posix/src/pthread.c, posix/src/pthreadexit.c,
     7        posix/src/setcancelstate.c, posix/src/setcanceltype.c,
     8        posix/src/testcancel.c, rtems/src/taskdelete.c,
     9        score/inline/rtems/score/object.inl, score/src/objectclose.c,
     10        score/src/threadclose.c: Make all task delete/exit/cancel routines
     11        follow the same critical section pattern. Also ensure that POSIX
     12        cancelation routines are run at thread exit.
     13
    1142008-05-22      Joel Sherrill <joel.sherrill@oarcorp.com>
    215
  • cpukit/itron/include/rtems/itron/task.h

    rcdc8309 r345fc11  
    7777
    7878/*
    79  *
    80  *  _ITRON_Delete_task
    81  */
    82 
    83 ER _ITRON_Delete_task(
    84   Thread_Control *the_thread
    85 );
    86 
    87 /*
    8879 * Return a status code and enable dispatching
    8980 */
  • cpukit/itron/src/del_tsk.c

    rcdc8309 r345fc11  
    11/*
    2  *  COPYRIGHT (c) 1989-2007.
     2 *  COPYRIGHT (c) 1989-2008.
    33 *  On-Line Applications Research Corporation (OAR).
    44 *
     
    2020#include <rtems/score/wkspace.h>
    2121#include <rtems/score/apiext.h>
     22#include <rtems/score/apimutex.h>
    2223#include <rtems/score/sysstate.h>
    2324
     
    3536  register Thread_Control *the_thread;
    3637  Objects_Locations        location;
     38  Objects_Information     *the_information;
    3739  ER                       result = E_OK; /* to avoid warning */
    3840
     41  _RTEMS_Lock_allocator();
    3942  the_thread = _ITRON_Task_Get( tskid, &location );
    4043  switch ( location ) {
     
    4346#endif
    4447    case OBJECTS_ERROR:
     48      _RTEMS_Unlock_allocator();
    4549      return _ITRON_Task_Clarify_get_id_error( tskid );
    4650
    4751    case OBJECTS_LOCAL:
    4852
    49       if ( _Thread_Is_executing( the_thread ) )
     53      if ( _Thread_Is_executing( the_thread ) ) {
     54        _RTEMS_Unlock_allocator();
    5055        _ITRON_return_errorno( E_OBJ );
     56      }
    5157
    52       if ( !_States_Is_dormant( the_thread->current_state ) )
     58      if ( !_States_Is_dormant( the_thread->current_state ) ) {
     59        _RTEMS_Unlock_allocator();
    5360        _ITRON_return_errorno( E_OBJ );
     61      }
    5462
    55       result = _ITRON_Delete_task( the_thread );
     63      the_information = _Objects_Get_information_id( the_thread->Object.id );
     64      _Thread_Close( the_information, the_thread );
     65
     66      _ITRON_Task_Free( the_thread );
     67
     68      _RTEMS_Unlock_allocator();
     69      result = E_OK;
    5670      break;
    5771  }
  • cpukit/itron/src/exd_tsk.c

    rcdc8309 r345fc11  
    2121#include <rtems/score/wkspace.h>
    2222#include <rtems/score/apiext.h>
     23#include <rtems/score/apimutex.h>
    2324#include <rtems/score/sysstate.h>
    2425
     
    3334  Objects_Information     *the_information;
    3435
     36  _RTEMS_Lock_allocator();
    3537  _Thread_Disable_dispatch();
    3638
    37   the_information = _Objects_Get_information_id( _Thread_Executing->Object.id );
     39    the_information = _Objects_Get_information_id(_Thread_Executing->Object.id);
    3840
    39   /* This should never happen if _Thread_Get() works right */
    40   assert( the_information );
     41    /* This should never happen if _Thread_Get() works right */
     42    assert( the_information );
    4143
    42   _Thread_Set_state( _Thread_Executing, STATES_DORMANT );
    43   _ITRON_Delete_task( _Thread_Executing );
     44    _Thread_Close( the_information, _Thread_Executing );
    4445
     46    _ITRON_Task_Free( _Thread_Executing );
     47
     48  _RTEMS_Unlock_allocator();
    4549  _Thread_Enable_dispatch();
    4650}
  • cpukit/itron/src/task.c

    rcdc8309 r345fc11  
    2020#include <rtems/score/wkspace.h>
    2121#include <rtems/score/apiext.h>
     22#include <rtems/score/apimutex.h>
    2223#include <rtems/score/sysstate.h>
    2324
     
    8384  if ( _ITRON_Initialize_user_tasks_p )
    8485    (*_ITRON_Initialize_user_tasks_p)();
    85 }
    86 
    87 /*PAGE
    88  *
    89  *  _ITRON_Delete_task
    90  */
    91 
    92 ER _ITRON_Delete_task(
    93   Thread_Control *the_thread
    94 )
    95 {
    96   Objects_Information     *the_information;
    97 
    98   the_information = _Objects_Get_information_id( the_thread->Object.id );
    99   if ( !the_information ) {
    100     return E_OBJ;             /* XXX - should never happen */
    101   }
    102 
    103   _Thread_Close( the_information, the_thread );
    104 
    105   _ITRON_Task_Free( the_thread );
    106 
    107   return E_OK;
    10886}
    10987
  • cpukit/posix/include/rtems/posix/threadsup.h

    rcdc8309 r345fc11  
    44
    55/*
    6  *  COPYRIGHT (c) 1989-2007.
     6 *  COPYRIGHT (c) 1989-2008.
    77 *  On-Line Applications Research Corporation (OAR).
    88 *
     
    2121#include <rtems/score/tqdata.h>
    2222
     23/*!
     24 *  This defines the POSIX API support structure associated with
     25 *  each thread in a system with POSIX configured.
     26 */
    2327typedef struct {
     28  /** This is the POSIX threads attribute set. */
    2429  pthread_attr_t          Attributes;
     30  /** This indicates whether the thread is attached or detached. */
    2531  int                     detachstate;
     32  /** This is the set of threads waiting for the thread to exit. */
    2633  Thread_queue_Control    Join_List;
     34  /** This is the thread's current scheduling policy. */
    2735  int                     schedpolicy;
     36  /** This is the thread's current set of scheduling parameters. */
    2837  struct sched_param      schedparam;
     38  /**
     39   *  This is the high priority to execute at when using the sporadic
     40   *  scheduler.
     41   */
    2942  int                     ss_high_priority;
     43  /**
     44   *  This is the timer which controls when the thread executes at
     45   *  high and low priority when using the sporadic scheduler.
     46   */
    3047  Watchdog_Control        Sporadic_timer;
    3148
     49  /** This is the set of signals which are currently blocked. */
    3250  sigset_t                signals_blocked;
     51  /** This is the set of signals which are currently pending. */
    3352  sigset_t                signals_pending;
    3453
    35   /*
    36    *  POSIX Cancelability
    37    */
     54  /*******************************************************************/
     55  /*******************************************************************/
     56  /***************         POSIX Cancelability         ***************/
     57  /*******************************************************************/
     58  /*******************************************************************/
     59
     60  /** This is the cancelability state. */
    3861  int                     cancelability_state;
     62  /** This is the cancelability type. */
    3963  int                     cancelability_type;
     64  /** This indicates if a cancelation has been requested. */
    4065  int                     cancelation_requested;
     66  /** This is the set of cancelation handlers. */
    4167  Chain_Control           Cancellation_Handlers;
    4268
    4369} POSIX_API_Control;
    4470
     71/*!
     72 *  @brief POSIX Thread Exit Shared Helper
     73 *
     74 *  This method is a helper routine which ensures that all
     75 *  POSIX thread calls which result in a thread exiting will
     76 *  do so in the same manner.
     77 *
     78 *  @param[in] the_thread is the thread exiting or being canceled
     79 *  @param[in] value_ptr is the value to be returned by the thread
     80 */
     81void _POSIX_Thread_Exit(
     82  Thread_Control *the_thread,
     83  void           *value_ptr
     84);
     85
    4586#endif
    4687/* end of include file */
  • cpukit/posix/src/cancel.c

    rcdc8309 r345fc11  
    11/*
    2  *  COPYRIGHT (c) 1989-2007.
     2 *  COPYRIGHT (c) 1989-2008.
    33 *  On-Line Applications Research Corporation (OAR).
    44 *
     
    3535)
    3636{
    37   Thread_Control                    *the_thread;
    38   POSIX_API_Control                 *thread_support;
    39   Objects_Locations                  location;
     37  Thread_Control     *the_thread;
     38  POSIX_API_Control  *thread_support;
     39  Objects_Locations   location;
     40  boolean             cancel = FALSE;
    4041
    4142  /*
     
    5556
    5657      if (thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
    57           thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS) {
    58         _POSIX_Threads_cancel_run( the_thread );
    59       }
     58          thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS)
     59        cancel = TRUE;
    6060
    6161      _Thread_Enable_dispatch();
     62      if ( cancel )
     63        _POSIX_Thread_Exit( the_thread, PTHREAD_CANCELED );
    6264      return 0;
    6365
  • cpukit/posix/src/cancelrun.c

    rcdc8309 r345fc11  
    2626#include <rtems/posix/threadsup.h>
    2727
    28 /*PAGE
    29  *
    30  *  _POSIX_Threads_cancel_run
    31  *
    32  */
    33 
    3428void _POSIX_Threads_cancel_run(
    3529  Thread_Control *the_thread
     
    5852    _Workspace_Free( handler );
    5953  }
    60 
    61   /* Now we can delete the thread */
    62 
    63   the_thread->Wait.return_argument = PTHREAD_CANCELED;
    64   _Thread_Close(
    65     _Objects_Get_information_id( the_thread->Object.id ),
    66     the_thread
    67   );
    68   _POSIX_Threads_Free( the_thread );
    69 
    7054}
  • cpukit/posix/src/pthread.c

    rcdc8309 r345fc11  
    11/*
    2  *  COPYRIGHT (c) 1989-2007.
     2 *  COPYRIGHT (c) 1989-2008.
    33 *  On-Line Applications Research Corporation (OAR).
    44 *
     
    219219   *  Run the POSIX cancellation handlers
    220220   */
    221 
     221  _POSIX_Threads_cancel_run( deleted );
     222
     223  /*
     224   *  Run all the key destructors
     225   */
    222226  _POSIX_Keys_Run_destructors( deleted );
    223227
     
    225229   *  Wakeup all the tasks which joined with this one
    226230   */
    227 
    228231  value_ptr = (void **) deleted->Wait.return_argument;
    229232
  • cpukit/posix/src/pthreadexit.c

    rcdc8309 r345fc11  
    2323
    2424#include <rtems/system.h>
     25#include <rtems/score/apimutex.h>
    2526#include <rtems/score/thread.h>
    2627#include <rtems/posix/pthread.h>
     28
     29void _POSIX_Thread_Exit(
     30  Thread_Control *the_thread,
     31  void           *value_ptr
     32)
     33{
     34  Objects_Information     *the_information;
     35
     36  the_information = _Objects_Get_information_id( the_thread->Object.id );
     37
     38  /*
     39   * The_information has to be non-NULL.  Otherwise, we couldn't be
     40   * running in a thread of this API and class.
     41   *
     42   * NOTE: Lock and unlock in different order so we do not throw a
     43   *       fatal error when locking the allocator mutex.  And after
     44   *       we unlock, we want to defer the context switch until we
     45   *       are ready to be switched out.  Otherwise, an ISR could
     46   *       occur and preempt us out while we still hold the
     47   *       allocator mutex.
     48   */
     49 
     50  _RTEMS_Lock_allocator();
     51    _Thread_Disable_dispatch();
     52
     53      the_thread->Wait.return_argument = value_ptr;
     54
     55      _Thread_Close( the_information, the_thread );
     56
     57      _POSIX_Threads_Free( the_thread );
     58
     59    _RTEMS_Unlock_allocator();
     60  _Thread_Enable_dispatch();
     61}
    2762
    2863void pthread_exit(
     
    3065)
    3166{
    32   Objects_Information     *the_information;
    33 
    34   the_information = _Objects_Get_information_id( _Thread_Executing->Object.id );
    35 
    36   /*
    37    * the_information has to be non-NULL.  Otherwise, we couldn't be
    38    * running in a thread of this API and class.
    39    */
    40  
    41   _Thread_Disable_dispatch();
    42 
    43   _Thread_Executing->Wait.return_argument = value_ptr;
    44 
    45   _Thread_Close( the_information, _Thread_Executing );
    46 
    47   _POSIX_Threads_Free( _Thread_Executing );
    48 
    49   _Thread_Enable_dispatch();
     67  _POSIX_Thread_Exit( _Thread_Executing, value_ptr );
    5068}
  • cpukit/posix/src/setcancelstate.c

    rcdc8309 r345fc11  
    11/*
    2  *  COPYRIGHT (c) 1989-2007.
     2 *  COPYRIGHT (c) 1989-2008.
    33 *  On-Line Applications Research Corporation (OAR).
    44 *
     
    3636)
    3737{
    38   POSIX_API_Control                 *thread_support;
     38  POSIX_API_Control *thread_support;
     39  boolean            cancel = FALSE;
    3940
    4041  /*
     
    6263         thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
    6364         thread_support->cancelation_requested )
    64       _POSIX_Threads_cancel_run( _Thread_Executing );
    65   _Thread_Enable_dispatch();
     65      cancel = TRUE;
    6666
     67 _Thread_Enable_dispatch();
     68 if ( cancel )
     69   _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED );
    6770  return 0;
    6871}
  • cpukit/posix/src/setcanceltype.c

    rcdc8309 r345fc11  
    11/*
    2  *  COPYRIGHT (c) 1989-2007.
     2 *  COPYRIGHT (c) 1989-2008.
    33 *  On-Line Applications Research Corporation (OAR).
    44 *
     
    3636)
    3737{
    38   POSIX_API_Control                 *thread_support;
     38  POSIX_API_Control *thread_support;
     39  boolean            cancel = FALSE;
    3940
    4041  /*
     
    6263         thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
    6364         thread_support->cancelation_requested )
    64       _POSIX_Threads_cancel_run( _Thread_Executing );
     65      cancel = TRUE;
    6566  _Thread_Enable_dispatch();
     67  if ( cancel )
     68    _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED );
    6669
    6770  return 0;
  • cpukit/posix/src/testcancel.c

    rcdc8309 r345fc11  
    11/*
    2  *  COPYRIGHT (c) 1989-2007.
     2 *  COPYRIGHT (c) 1989-2008.
    33 *  On-Line Applications Research Corporation (OAR).
    44 *
     
    3333void pthread_testcancel( void )
    3434{
    35   POSIX_API_Control                 *thread_support;
     35  POSIX_API_Control *thread_support;
     36  boolean            cancel = FALSE;
    3637
    3738  /*
     
    4950    if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
    5051         thread_support->cancelation_requested )
    51       _POSIX_Threads_cancel_run( _Thread_Executing );
     52      cancel = TRUE;
    5253  _Thread_Enable_dispatch();
     54
     55  if ( cancel )
     56    _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED );
    5357}
  • cpukit/rtems/src/taskdelete.c

    rcdc8309 r345fc11  
    6868      the_information = _Objects_Get_information_id( the_thread->Object.id );
    6969
    70 #if defined(RTEMS_DEBUG)
    71       if ( !the_information ) {
    72         _Thread_Enable_dispatch();
    73         return RTEMS_INVALID_ID;
    74         /* This should never happen if _Thread_Get() works right */
    75       }
    76 #endif
     70      #if defined(RTEMS_DEBUG)
     71        if ( !the_information ) {
     72          _Thread_Enable_dispatch();
     73          return RTEMS_INVALID_ID;
     74          /* This should never happen if _Thread_Get() works right */
     75        }
     76      #endif
     77
     78      #if defined(RTEMS_MULTIPROCESSING)
     79        if ( the_thread->is_global ) {
     80          _Objects_MP_Close( &_RTEMS_tasks_Information, the_thread->Object.id );
     81          _RTEMS_tasks_MP_Send_process_packet(
     82            RTEMS_TASKS_MP_ANNOUNCE_DELETE,
     83            the_thread->Object.id,
     84            0                                /* Not used */
     85          );
     86        }
     87      #endif
    7788
    7889      _Thread_Close( the_information, the_thread );
    7990
    8091      _RTEMS_tasks_Free( the_thread );
    81 
    82 #if defined(RTEMS_MULTIPROCESSING)
    83       if ( the_thread->is_global ) {
    84 
    85         _Objects_MP_Close( &_RTEMS_tasks_Information, the_thread->Object.id );
    86 
    87         _RTEMS_tasks_MP_Send_process_packet(
    88           RTEMS_TASKS_MP_ANNOUNCE_DELETE,
    89           the_thread->Object.id,
    90           0                                /* Not used */
    91         );
    92       }
    93 #endif
    9492
    9593      _RTEMS_Unlock_allocator();
  • cpukit/score/inline/rtems/score/object.inl

    rcdc8309 r345fc11  
    229229
    230230/**
     231 *  This function sets the pointer to the local_table object
     232 *  referenced by the index to a NULL so the object Id is invalid
     233 *  after this call.
     234 *
     235 *  @param[in] information points to an Object Information Table
     236 *  @param[in] the_object is the local object pointer
     237 *
     238 *  @note This routine is ONLY to be called in places where the
     239 *        index portion of the Id is known to be good.  This is
     240 *        OK since it is normally called from object create/init
     241 *        or delete/destroy operations.
     242 */
     243
     244RTEMS_INLINE_ROUTINE void _Objects_Invalidate_Id(
     245  Objects_Information  *information,
     246  Objects_Control      *the_object
     247)
     248{
     249  _Objects_Set_local_object(
     250    information,
     251    _Objects_Get_index( the_object->id ),
     252    NULL
     253  );
     254}
     255
     256/**
    231257 *  This function places the_object control pointer and object name
    232258 *  in the Local Pointer and Local Name Tables, respectively.
  • cpukit/score/src/objectclose.c

    rcdc8309 r345fc11  
    2323)
    2424{
    25   _Objects_Set_local_object(
    26     information,
    27     _Objects_Get_index( the_object->id ),
    28     NULL
    29   );
     25  _Objects_Invalidate_Id( information, the_object );
    3026
    3127  _Objects_Namespace_remove( information, the_object );
  • cpukit/score/src/threadclose.c

    rcdc8309 r345fc11  
    4646)
    4747{
     48
     49  /*
     50   *  Now we are in a dispatching critical section again and we
     51   *  can take the thread OUT of the published set.  It is invalid
     52   *  to use this thread's Id after this call.  This will prevent
     53   *  any other task from attempting to initiate a call on this task.
     54   */
     55  _Objects_Invalidate_Id( information, &the_thread->Object );
     56
    4857  /*
    4958   *  We assume the Allocator Mutex is locked when we get here.
     
    6271   *  Now we are in a dispatching critical section again and we
    6372   *  can take the thread OUT of the published set.  It is invalid
    64    *  to use this thread's Id after this call.
     73   *  to use this thread's Id OR name after this call.
    6574   */
    6675  _Objects_Close( information, &the_thread->Object );
Note: See TracChangeset for help on using the changeset viewer.