Changeset 8faca06 in rtems


Ignore:
Timestamp:
04/22/96 16:46:36 (27 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
f5674938
Parents:
6365f81
Message:

thread.c: added support for optional user provided stack allocator

wkspace.c: made initialization routine a regular subroutine

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/score/src/thread.c

    r6365f81 r8faca06  
    5151  unsigned32      index;
    5252
     53  /*
     54   * BOTH stacks hooks must be set or both must be NULL.
     55   * Do not allow mixture.
     56   */
     57
     58  if ( !( ( _CPU_Table.stack_allocate_hook == 0 )
     59       == ( _CPU_Table.stack_free_hook == 0 ) ) )
     60    _Internal_error_Occurred(
     61      INTERNAL_ERROR_CORE,
     62      TRUE,
     63      INTERNAL_ERROR_BAD_STACK_HOOK
     64    );
     65
    5366  _Context_Switch_necessary = FALSE;
    5467  _Thread_Executing         = NULL;
     
    284297/*PAGE
    285298 *
     299 *  _Thread_Stack_Allocate
     300 *
     301 *  Allocate the requested stack space for the thread.
     302 *  return the actual size allocated after any adjustment
     303 *  or return zero if the allocation failed.
     304 *  Set the Start.stack field to the address of the stack
     305 */
     306
     307static unsigned32 _Thread_Stack_Allocate(
     308  Thread_Control *the_thread,
     309  unsigned32 stack_size)
     310{
     311  void *stack_addr = 0;
     312 
     313  if ( !_Stack_Is_enough( stack_size ) )
     314    stack_size = STACK_MINIMUM_SIZE;
     315 
     316  /*
     317   * Call ONLY the CPU table stack allocate hook, _or_ the
     318   * the RTEMS workspace allocate.  This is so the stack free
     319   * routine can call the correct deallocation routine.
     320   */
     321  if ( _CPU_Table.stack_allocate_hook )
     322  {
     323    stack_addr = (*_CPU_Table.stack_allocate_hook)( stack_size );
     324  } else {
     325    stack_size = _Stack_Adjust_size( stack_size );
     326    stack_addr = _Workspace_Allocate( stack_size );
     327  }
     328 
     329  if ( !stack_addr )
     330      stack_size = 0;
     331 
     332  the_thread->Start.stack = stack_addr;
     333 
     334  return stack_size;
     335}
     336
     337/*
     338 *  _Thread_Stack_Free
     339 *
     340 *  Deallocate the Thread's stack.
     341 */
     342
     343static void _Thread_Stack_Free(void *stack_addr)
     344{
     345    /*
     346     * Call ONLY the CPU table stack free hook, or the
     347     * the RTEMS workspace free.  This is so the free
     348     * routine properly matches the allocation of the stack.
     349     */
     350    if ( _CPU_Table.stack_free_hook )
     351        (*_CPU_Table.stack_free_hook)( stack_addr );
     352    else
     353        _Workspace_Free( stack_addr );
     354}
     355
     356/*PAGE
     357 *
    286358 *  _Thread_Initialize
    287359 *
     
    321393
    322394  if ( !stack ) {
    323     stack = _Workspace_Allocate( actual_stack_size );
    324  
    325     if ( !stack )
    326       return FALSE;
    327 
    328     the_thread->Start.stack = stack;
     395    actual_stack_size = _Thread_Stack_Allocate( the_thread, stack_size );
     396 
     397    if ( !actual_stack_size )
     398      return FALSE;                     /* stack allocation failed */
     399
     400    stack = the_thread->Start.stack;
    329401  } else
    330402    the_thread->Start.stack = NULL;
     
    345417    if ( !fp_area ) {
    346418      if ( the_thread->Start.stack )
    347         (void) _Workspace_Free( the_thread->Start.stack );
     419        (void) _Thread_Stack_Free( the_thread->Start.stack );
    348420      return FALSE;
    349421    }
     
    358430
    359431  /*
    360    *  Allocate the floating point area for this thread
     432   *  Allocate the extensions area for this thread
    361433   */
    362434
     
    371443
    372444      if ( the_thread->Start.stack )
    373         (void) _Workspace_Free( the_thread->Start.stack );
     445        (void) _Thread_Stack_Free( the_thread->Start.stack );
    374446
    375447      return FALSE;
     
    414486
    415487    if ( the_thread->Start.stack )
    416       (void) _Workspace_Free( the_thread->Start.stack );
     488      (void) _Thread_Stack_Free( the_thread->Start.stack );
    417489
    418490    return FALSE;
  • c/src/exec/score/src/wkspace.c

    r6365f81 r8faca06  
    2323/*PAGE
    2424 *
     25 *  _Workspace_Handler_initialization
     26 */
     27 
     28void _Workspace_Handler_initialization(
     29  void       *starting_address,
     30  unsigned32  size
     31)
     32{
     33  unsigned32 *zero_out_array;
     34  unsigned32  index;
     35  unsigned32  memory_available;
     36 
     37  if ( !starting_address || !_Addresses_Is_aligned( starting_address ) )
     38    _Internal_error_Occurred(
     39      INTERNAL_ERROR_CORE,
     40      TRUE,
     41      INTERNAL_ERROR_INVALID_WORKSPACE_ADDRESS
     42    );
     43 
     44  if ( _CPU_Table.do_zero_of_workspace ) {
     45    for( zero_out_array  = (unsigned32 *) starting_address, index = 0 ;
     46         index < size / 4 ;
     47         index++ )
     48      zero_out_array[ index ] = 0;
     49  }
     50 
     51  memory_available = _Heap_Initialize(
     52    &_Workspace_Area,
     53    starting_address,
     54    size,
     55    CPU_HEAP_ALIGNMENT
     56  );
     57 
     58  if ( memory_available == 0 )
     59    _Internal_error_Occurred(
     60      INTERNAL_ERROR_CORE,
     61      TRUE,
     62      INTERNAL_ERROR_TOO_LITTLE_WORKSPACE
     63    );
     64}
     65
     66/*PAGE
     67 *
    2568 *  _Workspace_Allocate_or_fatal_error
    2669 *
  • cpukit/score/src/thread.c

    r6365f81 r8faca06  
    5151  unsigned32      index;
    5252
     53  /*
     54   * BOTH stacks hooks must be set or both must be NULL.
     55   * Do not allow mixture.
     56   */
     57
     58  if ( !( ( _CPU_Table.stack_allocate_hook == 0 )
     59       == ( _CPU_Table.stack_free_hook == 0 ) ) )
     60    _Internal_error_Occurred(
     61      INTERNAL_ERROR_CORE,
     62      TRUE,
     63      INTERNAL_ERROR_BAD_STACK_HOOK
     64    );
     65
    5366  _Context_Switch_necessary = FALSE;
    5467  _Thread_Executing         = NULL;
     
    284297/*PAGE
    285298 *
     299 *  _Thread_Stack_Allocate
     300 *
     301 *  Allocate the requested stack space for the thread.
     302 *  return the actual size allocated after any adjustment
     303 *  or return zero if the allocation failed.
     304 *  Set the Start.stack field to the address of the stack
     305 */
     306
     307static unsigned32 _Thread_Stack_Allocate(
     308  Thread_Control *the_thread,
     309  unsigned32 stack_size)
     310{
     311  void *stack_addr = 0;
     312 
     313  if ( !_Stack_Is_enough( stack_size ) )
     314    stack_size = STACK_MINIMUM_SIZE;
     315 
     316  /*
     317   * Call ONLY the CPU table stack allocate hook, _or_ the
     318   * the RTEMS workspace allocate.  This is so the stack free
     319   * routine can call the correct deallocation routine.
     320   */
     321  if ( _CPU_Table.stack_allocate_hook )
     322  {
     323    stack_addr = (*_CPU_Table.stack_allocate_hook)( stack_size );
     324  } else {
     325    stack_size = _Stack_Adjust_size( stack_size );
     326    stack_addr = _Workspace_Allocate( stack_size );
     327  }
     328 
     329  if ( !stack_addr )
     330      stack_size = 0;
     331 
     332  the_thread->Start.stack = stack_addr;
     333 
     334  return stack_size;
     335}
     336
     337/*
     338 *  _Thread_Stack_Free
     339 *
     340 *  Deallocate the Thread's stack.
     341 */
     342
     343static void _Thread_Stack_Free(void *stack_addr)
     344{
     345    /*
     346     * Call ONLY the CPU table stack free hook, or the
     347     * the RTEMS workspace free.  This is so the free
     348     * routine properly matches the allocation of the stack.
     349     */
     350    if ( _CPU_Table.stack_free_hook )
     351        (*_CPU_Table.stack_free_hook)( stack_addr );
     352    else
     353        _Workspace_Free( stack_addr );
     354}
     355
     356/*PAGE
     357 *
    286358 *  _Thread_Initialize
    287359 *
     
    321393
    322394  if ( !stack ) {
    323     stack = _Workspace_Allocate( actual_stack_size );
    324  
    325     if ( !stack )
    326       return FALSE;
    327 
    328     the_thread->Start.stack = stack;
     395    actual_stack_size = _Thread_Stack_Allocate( the_thread, stack_size );
     396 
     397    if ( !actual_stack_size )
     398      return FALSE;                     /* stack allocation failed */
     399
     400    stack = the_thread->Start.stack;
    329401  } else
    330402    the_thread->Start.stack = NULL;
     
    345417    if ( !fp_area ) {
    346418      if ( the_thread->Start.stack )
    347         (void) _Workspace_Free( the_thread->Start.stack );
     419        (void) _Thread_Stack_Free( the_thread->Start.stack );
    348420      return FALSE;
    349421    }
     
    358430
    359431  /*
    360    *  Allocate the floating point area for this thread
     432   *  Allocate the extensions area for this thread
    361433   */
    362434
     
    371443
    372444      if ( the_thread->Start.stack )
    373         (void) _Workspace_Free( the_thread->Start.stack );
     445        (void) _Thread_Stack_Free( the_thread->Start.stack );
    374446
    375447      return FALSE;
     
    414486
    415487    if ( the_thread->Start.stack )
    416       (void) _Workspace_Free( the_thread->Start.stack );
     488      (void) _Thread_Stack_Free( the_thread->Start.stack );
    417489
    418490    return FALSE;
  • cpukit/score/src/wkspace.c

    r6365f81 r8faca06  
    2323/*PAGE
    2424 *
     25 *  _Workspace_Handler_initialization
     26 */
     27 
     28void _Workspace_Handler_initialization(
     29  void       *starting_address,
     30  unsigned32  size
     31)
     32{
     33  unsigned32 *zero_out_array;
     34  unsigned32  index;
     35  unsigned32  memory_available;
     36 
     37  if ( !starting_address || !_Addresses_Is_aligned( starting_address ) )
     38    _Internal_error_Occurred(
     39      INTERNAL_ERROR_CORE,
     40      TRUE,
     41      INTERNAL_ERROR_INVALID_WORKSPACE_ADDRESS
     42    );
     43 
     44  if ( _CPU_Table.do_zero_of_workspace ) {
     45    for( zero_out_array  = (unsigned32 *) starting_address, index = 0 ;
     46         index < size / 4 ;
     47         index++ )
     48      zero_out_array[ index ] = 0;
     49  }
     50 
     51  memory_available = _Heap_Initialize(
     52    &_Workspace_Area,
     53    starting_address,
     54    size,
     55    CPU_HEAP_ALIGNMENT
     56  );
     57 
     58  if ( memory_available == 0 )
     59    _Internal_error_Occurred(
     60      INTERNAL_ERROR_CORE,
     61      TRUE,
     62      INTERNAL_ERROR_TOO_LITTLE_WORKSPACE
     63    );
     64}
     65
     66/*PAGE
     67 *
    2568 *  _Workspace_Allocate_or_fatal_error
    2669 *
Note: See TracChangeset for help on using the changeset viewer.