Changeset 2cd5444 in rtems


Ignore:
Timestamp:
Nov 2, 1999, 3:58:39 PM (20 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
32441ab7
Parents:
8f0529f
Message:

Added code to allocate by index. This is the object ID style used
by ITRON.

Corrected spacing.

Files:
2 edited

Legend:

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

    r8f0529f r2cd5444  
    126126   
    127127    /*
    128      *  Growing the tables means allocating a new area, doing a copy and updating
    129      *  the information table.
     128     *  Growing the tables means allocating a new area, doing a copy and
     129     *  updating the information table.
    130130     *
    131      *  If the maximum is minimum we do not have a table to copy. First time through.
     131     *  If the maximum is minimum we do not have a table to copy. First
     132     *  time through.
    132133     *
    133134     *  The allocation has :
    134135     *
    135136     *      void            *objects[block_count];
    136      *      unsiged32        inactive_count[block_count];
     137     *      unsigned32       inactive_count[block_count];
    137138     *      Objects_Name    *name_table[block_count];
    138139     *      Objects_Control *local_table[maximum];
     
    157158      object_blocks = (void**)
    158159        _Workspace_Allocate(
    159           block_count * (sizeof(void *) + sizeof(unsigned32) + sizeof(Objects_Name *)) +
     160          block_count *
     161             (sizeof(void *) + sizeof(unsigned32) + sizeof(Objects_Name *)) +
    160162          ((maximum + minimum_index) * sizeof(Objects_Control *))
    161163          );
     
    167169      object_blocks = (void**)
    168170        _Workspace_Allocate_or_fatal_error(
    169           block_count * (sizeof(void *) + sizeof(unsigned32) + sizeof(Objects_Name *)) +
     171          block_count *
     172             (sizeof(void *) + sizeof(unsigned32) + sizeof(Objects_Name *)) +
    170173          ((maximum + minimum_index) * sizeof(Objects_Control *))
    171174        );
     
    177180     */
    178181     
    179     inactive_per_block =
    180       (unsigned32 *) _Addresses_Add_offset( object_blocks, block_count * sizeof(void*) );
    181     name_table =
    182         (Objects_Name *) _Addresses_Add_offset( inactive_per_block,
    183                                                 block_count * sizeof(unsigned32) );
    184     local_table =
    185       (Objects_Control **) _Addresses_Add_offset( name_table,
    186                                                   block_count * sizeof(Objects_Name *) );
     182    inactive_per_block = (unsigned32 *) _Addresses_Add_offset(
     183        object_blocks, block_count * sizeof(void*) );
     184    name_table = (Objects_Name *) _Addresses_Add_offset(
     185        inactive_per_block, block_count * sizeof(unsigned32) );
     186    local_table = (Objects_Control **) _Addresses_Add_offset(
     187        name_table, block_count * sizeof(Objects_Name *) );
    187188   
    188189    /*
    189      *  Take the block count down. Saves all the (block_count - 1) in the copies.
     190     *  Take the block count down. Saves all the (block_count - 1)
     191     *  in the copies.
    190192     */
    191193
     
    418420 *
    419421 *  Input parameters:
    420  *    information     - object information table
    421  *    the_class       - object class
    422  *    supports_global - TRUE if this is a global object class
    423  *    maximum         - maximum objects of this class
    424  *    is_string       - TRUE if names for this object are strings
    425  *    size            - size of this object's control block
    426  *    is_thread       - TRUE if this class is threads
     422 *    information         - object information table
     423 *    the_class           - object class
     424 *    supports_global     - TRUE if this is a global object class
     425 *    maximum             - maximum objects of this class
     426 *    size                - size of this object's control block
     427 *    is_string           - TRUE if names for this object are strings
     428 *    maximum_name_length - maximum length of each object's name
     429 *    is_thread           - TRUE if this class is threads
    427430 *
    428431 *  Output parameters:  NONE
     
    584587      unsigned32 block;
    585588   
    586       block =
    587         _Objects_Get_index( the_object->id ) - _Objects_Get_index( information->minimum_id );
     589      block = _Objects_Get_index( the_object->id ) -
     590              _Objects_Get_index( information->minimum_id );
    588591      block /= information->allocation_size;
    589592     
     
    595598  return the_object;
    596599}
     600
     601/*PAGE
     602 *
     603 *  _Objects_Allocate_by_index
     604 *
     605 *  DESCRIPTION:
     606 *
     607 *  This function allocates the object control block
     608 *  specified by the index from the inactive chain of
     609 *  free object control blocks.
     610 */
     611
     612Objects_Control *_Objects_Allocate_by_index(
     613  Objects_Information *information,
     614  unsigned32           index,
     615  unsigned32           sizeof_control
     616)
     617{
     618  Objects_Control *the_object;
     619  void            *p;
     620
     621  if ( index && information->maximum >= index ) {
     622    the_object = _Objects_Get_local_object( information, index );
     623    if ( the_object )
     624      return NULL;
     625
     626    /* XXX
     627     *  This whole section of code needs to be addressed.
     628     *    +  The 0 should be dealt with more properly so we can autoextend.
     629     *    +  The pointer arithmetic is probably too expensive.
     630     *    +  etc.
     631     */
     632   
     633    p = _Addresses_Add_offset( information->object_blocks[ 0 ],
     634        (information->allocation_size * information->name_length) ),
     635
     636    p = _Addresses_Add_offset( p, (sizeof_control * (index - 1)) );
     637    the_object = (Objects_Control *)p;
     638    _Chain_Extract( &the_object->Node );
     639 
     640    return the_object;   
     641  }   
     642
     643  /*
     644   *  Autoextend will have to be thought out as it applies
     645   *  to user assigned indices.
     646   */
     647
     648  return NULL;
     649}
     650
     651
    597652
    598653/*PAGE
     
    834889 *
    835890 * Output parameters:
    836  *   returns - address of object if local
    837  *   location    - one of the following:
     891 *   returns  - address of object if local
     892 *   location - one of the following:
    838893 *                  OBJECTS_ERROR  - invalid object ID
    839894 *                  OBJECTS_REMOTE - remote object
     
    864919  *location = OBJECTS_ERROR;
    865920#if defined(RTEMS_MULTIPROCESSING)
    866   _Objects_MP_Is_remote( information, id, location, &the_object );
     921  _Objects_MP_Is_remote(
     922    information,
     923    _Objects_Build_id( information->the_class, _Objects_Local_node, index ),
     924    location,
     925    &the_object
     926  );
    867927  return the_object;
    868928#else
     
    871931}
    872932
     933/*PAGE
     934 *
     935 * _Objects_Get_by_index
     936 *
     937 * This routine sets the object pointer for the given
     938 * object id based on the given object information structure.
     939 *
     940 * Input parameters:
     941 *   information - pointer to entry in table for this class
     942 *   index       - object index to check for
     943 *   location    - address of where to store the location
     944 *
     945 * Output parameters:
     946 *   returns  - address of object if local
     947 *   location - one of the following:
     948 *                  OBJECTS_ERROR  - invalid object ID
     949 *                  OBJECTS_REMOTE - remote object
     950 *                  OBJECTS_LOCAL  - local object
     951 */
     952
     953Objects_Control *_Objects_Get_by_index(
     954  Objects_Information *information,
     955  unsigned32           index,
     956  Objects_Locations   *location
     957)
     958{
     959  Objects_Control *the_object;
     960
     961  if ( information->maximum >= index ) {
     962    _Thread_Disable_dispatch();
     963    if ( (the_object = _Objects_Get_local_object( information, index )) != NULL ) {
     964      *location = OBJECTS_LOCAL;
     965      return( the_object );
     966    }
     967    _Thread_Enable_dispatch();
     968    *location = OBJECTS_ERROR;
     969    return( NULL );
     970  }
     971
     972  /*
     973   *  With just an index, you can't access a remote object.
     974   */
     975
     976  _Thread_Enable_dispatch();
     977  *location = OBJECTS_ERROR;
     978  return NULL;
     979}
    873980
    874981/*PAGE
  • cpukit/score/src/object.c

    r8f0529f r2cd5444  
    126126   
    127127    /*
    128      *  Growing the tables means allocating a new area, doing a copy and updating
    129      *  the information table.
     128     *  Growing the tables means allocating a new area, doing a copy and
     129     *  updating the information table.
    130130     *
    131      *  If the maximum is minimum we do not have a table to copy. First time through.
     131     *  If the maximum is minimum we do not have a table to copy. First
     132     *  time through.
    132133     *
    133134     *  The allocation has :
    134135     *
    135136     *      void            *objects[block_count];
    136      *      unsiged32        inactive_count[block_count];
     137     *      unsigned32       inactive_count[block_count];
    137138     *      Objects_Name    *name_table[block_count];
    138139     *      Objects_Control *local_table[maximum];
     
    157158      object_blocks = (void**)
    158159        _Workspace_Allocate(
    159           block_count * (sizeof(void *) + sizeof(unsigned32) + sizeof(Objects_Name *)) +
     160          block_count *
     161             (sizeof(void *) + sizeof(unsigned32) + sizeof(Objects_Name *)) +
    160162          ((maximum + minimum_index) * sizeof(Objects_Control *))
    161163          );
     
    167169      object_blocks = (void**)
    168170        _Workspace_Allocate_or_fatal_error(
    169           block_count * (sizeof(void *) + sizeof(unsigned32) + sizeof(Objects_Name *)) +
     171          block_count *
     172             (sizeof(void *) + sizeof(unsigned32) + sizeof(Objects_Name *)) +
    170173          ((maximum + minimum_index) * sizeof(Objects_Control *))
    171174        );
     
    177180     */
    178181     
    179     inactive_per_block =
    180       (unsigned32 *) _Addresses_Add_offset( object_blocks, block_count * sizeof(void*) );
    181     name_table =
    182         (Objects_Name *) _Addresses_Add_offset( inactive_per_block,
    183                                                 block_count * sizeof(unsigned32) );
    184     local_table =
    185       (Objects_Control **) _Addresses_Add_offset( name_table,
    186                                                   block_count * sizeof(Objects_Name *) );
     182    inactive_per_block = (unsigned32 *) _Addresses_Add_offset(
     183        object_blocks, block_count * sizeof(void*) );
     184    name_table = (Objects_Name *) _Addresses_Add_offset(
     185        inactive_per_block, block_count * sizeof(unsigned32) );
     186    local_table = (Objects_Control **) _Addresses_Add_offset(
     187        name_table, block_count * sizeof(Objects_Name *) );
    187188   
    188189    /*
    189      *  Take the block count down. Saves all the (block_count - 1) in the copies.
     190     *  Take the block count down. Saves all the (block_count - 1)
     191     *  in the copies.
    190192     */
    191193
     
    418420 *
    419421 *  Input parameters:
    420  *    information     - object information table
    421  *    the_class       - object class
    422  *    supports_global - TRUE if this is a global object class
    423  *    maximum         - maximum objects of this class
    424  *    is_string       - TRUE if names for this object are strings
    425  *    size            - size of this object's control block
    426  *    is_thread       - TRUE if this class is threads
     422 *    information         - object information table
     423 *    the_class           - object class
     424 *    supports_global     - TRUE if this is a global object class
     425 *    maximum             - maximum objects of this class
     426 *    size                - size of this object's control block
     427 *    is_string           - TRUE if names for this object are strings
     428 *    maximum_name_length - maximum length of each object's name
     429 *    is_thread           - TRUE if this class is threads
    427430 *
    428431 *  Output parameters:  NONE
     
    584587      unsigned32 block;
    585588   
    586       block =
    587         _Objects_Get_index( the_object->id ) - _Objects_Get_index( information->minimum_id );
     589      block = _Objects_Get_index( the_object->id ) -
     590              _Objects_Get_index( information->minimum_id );
    588591      block /= information->allocation_size;
    589592     
     
    595598  return the_object;
    596599}
     600
     601/*PAGE
     602 *
     603 *  _Objects_Allocate_by_index
     604 *
     605 *  DESCRIPTION:
     606 *
     607 *  This function allocates the object control block
     608 *  specified by the index from the inactive chain of
     609 *  free object control blocks.
     610 */
     611
     612Objects_Control *_Objects_Allocate_by_index(
     613  Objects_Information *information,
     614  unsigned32           index,
     615  unsigned32           sizeof_control
     616)
     617{
     618  Objects_Control *the_object;
     619  void            *p;
     620
     621  if ( index && information->maximum >= index ) {
     622    the_object = _Objects_Get_local_object( information, index );
     623    if ( the_object )
     624      return NULL;
     625
     626    /* XXX
     627     *  This whole section of code needs to be addressed.
     628     *    +  The 0 should be dealt with more properly so we can autoextend.
     629     *    +  The pointer arithmetic is probably too expensive.
     630     *    +  etc.
     631     */
     632   
     633    p = _Addresses_Add_offset( information->object_blocks[ 0 ],
     634        (information->allocation_size * information->name_length) ),
     635
     636    p = _Addresses_Add_offset( p, (sizeof_control * (index - 1)) );
     637    the_object = (Objects_Control *)p;
     638    _Chain_Extract( &the_object->Node );
     639 
     640    return the_object;   
     641  }   
     642
     643  /*
     644   *  Autoextend will have to be thought out as it applies
     645   *  to user assigned indices.
     646   */
     647
     648  return NULL;
     649}
     650
     651
    597652
    598653/*PAGE
     
    834889 *
    835890 * Output parameters:
    836  *   returns - address of object if local
    837  *   location    - one of the following:
     891 *   returns  - address of object if local
     892 *   location - one of the following:
    838893 *                  OBJECTS_ERROR  - invalid object ID
    839894 *                  OBJECTS_REMOTE - remote object
     
    864919  *location = OBJECTS_ERROR;
    865920#if defined(RTEMS_MULTIPROCESSING)
    866   _Objects_MP_Is_remote( information, id, location, &the_object );
     921  _Objects_MP_Is_remote(
     922    information,
     923    _Objects_Build_id( information->the_class, _Objects_Local_node, index ),
     924    location,
     925    &the_object
     926  );
    867927  return the_object;
    868928#else
     
    871931}
    872932
     933/*PAGE
     934 *
     935 * _Objects_Get_by_index
     936 *
     937 * This routine sets the object pointer for the given
     938 * object id based on the given object information structure.
     939 *
     940 * Input parameters:
     941 *   information - pointer to entry in table for this class
     942 *   index       - object index to check for
     943 *   location    - address of where to store the location
     944 *
     945 * Output parameters:
     946 *   returns  - address of object if local
     947 *   location - one of the following:
     948 *                  OBJECTS_ERROR  - invalid object ID
     949 *                  OBJECTS_REMOTE - remote object
     950 *                  OBJECTS_LOCAL  - local object
     951 */
     952
     953Objects_Control *_Objects_Get_by_index(
     954  Objects_Information *information,
     955  unsigned32           index,
     956  Objects_Locations   *location
     957)
     958{
     959  Objects_Control *the_object;
     960
     961  if ( information->maximum >= index ) {
     962    _Thread_Disable_dispatch();
     963    if ( (the_object = _Objects_Get_local_object( information, index )) != NULL ) {
     964      *location = OBJECTS_LOCAL;
     965      return( the_object );
     966    }
     967    _Thread_Enable_dispatch();
     968    *location = OBJECTS_ERROR;
     969    return( NULL );
     970  }
     971
     972  /*
     973   *  With just an index, you can't access a remote object.
     974   */
     975
     976  _Thread_Enable_dispatch();
     977  *location = OBJECTS_ERROR;
     978  return NULL;
     979}
    873980
    874981/*PAGE
Note: See TracChangeset for help on using the changeset viewer.