Changeset 40dcafa in rtems


Ignore:
Timestamp:
08/02/14 14:22:31 (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
60fe374
Parents:
b767683a
git-author:
Sebastian Huber <sebastian.huber@…> (08/02/14 14:22:31)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/05/14 07:30:33)
Message:

Add and use RTEMS_CONTAINER_OF()

Files:
21 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/src/bdbuf.c

    rb767683a r40dcafa  
    31793179    while ((node = rtems_chain_get_unprotected (chain)) != NULL)
    31803180    {
    3181       rtems_disk_device *dd = (rtems_disk_device *)
    3182         ((char *) node - offsetof (rtems_disk_device, read_ahead.node));
     3181      rtems_disk_device *dd =
     3182        RTEMS_CONTAINER_OF (node, rtems_disk_device, read_ahead.node);
    31833183      rtems_blkdev_bnum block = dd->read_ahead.next;
    31843184      rtems_blkdev_bnum media_block = 0;
  • cpukit/posix/include/rtems/posix/keyimpl.h

    rb767683a r40dcafa  
    4949 */
    5050POSIX_EXTERN Freechain_Control _POSIX_Keys_Keypool;
     51
     52#define POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ) \
     53  RTEMS_CONTAINER_OF( node, POSIX_Keys_Key_value_pair, Key_value_lookup_node )
    5154
    5255/**
  • cpukit/posix/src/key.c

    rb767683a r40dcafa  
    5555  int diff;
    5656
    57   n1 = _RBTree_Container_of( node1, POSIX_Keys_Key_value_pair, Key_value_lookup_node );
    58   n2 = _RBTree_Container_of( node2, POSIX_Keys_Key_value_pair, Key_value_lookup_node );
     57  n1 = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node1 );
     58  n2 = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node2 );
    5959
    6060  diff = n1->key - n2->key;
  • cpukit/posix/src/keyfreememory.c

    rb767683a r40dcafa  
    4040   */
    4141  next = _RBTree_Next( iter, RBT_LEFT );
    42   p = _RBTree_Container_of( next, POSIX_Keys_Key_value_pair, Key_value_lookup_node );
     42  p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( next );
    4343  while ( next != NULL && p->key == key_id) {
    4444    iter = next;
    4545    next = _RBTree_Next( iter, RBT_LEFT );
    46     p = _RBTree_Container_of( next, POSIX_Keys_Key_value_pair, Key_value_lookup_node );
     46    p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( next );
    4747  }
    4848
     
    5050   * delete all nodes belongs to the_key from the rbtree and chain.
    5151   */
    52   p = _RBTree_Container_of( iter, POSIX_Keys_Key_value_pair, Key_value_lookup_node );
     52  p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( iter );
    5353  while ( iter != NULL && p->key == key_id ) {
    5454    next = _RBTree_Next( iter, RBT_RIGHT );
     
    5858
    5959    iter = next;
    60     p = _RBTree_Container_of( iter, POSIX_Keys_Key_value_pair, Key_value_lookup_node );
     60    p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( iter );
    6161  }
    6262}
  • cpukit/posix/src/keygetspecific.c

    rb767683a r40dcafa  
    5252      p = _POSIX_Keys_Find( key, _Thread_Executing->Object.id, &search_node );
    5353      if ( p != NULL ) {
    54         value_pair_p = _RBTree_Container_of( p,
    55                                           POSIX_Keys_Key_value_pair,
    56                                           Key_value_lookup_node );
     54        value_pair_p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( p );
    5755        key_data = value_pair_p->value;
    5856      } else {
  • cpukit/posix/src/keysetspecific.c

    rb767683a r40dcafa  
    4747      p = _POSIX_Keys_Find( key, _Thread_Executing->Object.id, &search_node );
    4848      if ( p != NULL ) {
    49         value_pair_ptr = _RBTree_Container_of( p,
    50                                           POSIX_Keys_Key_value_pair,
    51                                           Key_value_lookup_node );
    52 
     49        value_pair_ptr = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( p );
    5350        value_pair_ptr->value = value;
    5451      } else {
  • cpukit/sapi/include/rtems/rbheap.h

    rb767683a r40dcafa  
    255255
    256256#define rtems_rbheap_chunk_of_node(node) \
    257   rtems_rbtree_container_of(node, rtems_rbheap_chunk, tree_node)
     257  RTEMS_CONTAINER_OF(node, rtems_rbheap_chunk, tree_node)
    258258
    259259static inline bool rtems_rbheap_is_chunk_free(const rtems_rbheap_chunk *chunk)
  • cpukit/sapi/include/rtems/rbtree.h

    rb767683a r40dcafa  
    7575
    7676/**
    77   * @brief macro to return the structure containing the @a node.
    78   *
    79   * This macro returns a pointer of type @a object_type that points
    80   * to the structure containing @a node, where @a object_member is the
    81   * field name of the rtems_rbtree_node structure in objects of @a object_type.
    82   */
    83 #define rtems_rbtree_container_of(node,object_type, object_member) \
    84   _RBTree_Container_of(node,object_type,object_member)
    85 
    86 /**
    8777 * @brief Initialize a RBTree header.
    8878 *
  • cpukit/score/include/rtems/score/basedefs.h

    rb767683a r40dcafa  
    218218#define RTEMS_ZERO_LENGTH_ARRAY 0
    219219
     220/**
     221 * @brief Returns a pointer to the container of a specified member pointer.
     222 *
     223 * @param[in] _m The pointer to a member of the container.
     224 * @param[in] _type The type of the container.
     225 * @param[in] _member_name The designator name of the container member.
     226 */
     227#define RTEMS_CONTAINER_OF( _m, _type, _member_name ) \
     228  ( (_type *) ( (uintptr_t) ( _m ) - offsetof( _type, _member_name ) ) )
     229
    220230#ifndef ASM
    221231  #ifdef RTEMS_DEPRECATED_TYPES
  • cpukit/score/include/rtems/score/mrspimpl.h

    rb767683a r40dcafa  
    182182  _Scheduler_Thread_change_resource_root(
    183183    executing,
    184     _Thread_Resource_node_to_thread( _Resource_Node_get_root( owner ) )
     184    THREAD_RESOURCE_NODE_TO_THREAD( _Resource_Node_get_root( owner ) )
    185185  );
    186186
  • cpukit/score/include/rtems/score/rbtree.h

    rb767683a r40dcafa  
    8383
    8484/**
    85  * @brief Macro to return the structure containing the @a node.
    86  *
    87  * This macro returns a pointer of type @a container_type that points
    88  * to the structure containing @a node, where @a node_field_name is the
    89  * field name of the RBTree_Node structure in @a container_type.
    90  *
    91  */
    92 #define _RBTree_Container_of(node, container_type, node_field_name) \
    93 ( \
    94   (container_type*) \
    95     ( (uintptr_t)(node) - offsetof(container_type, node_field_name) ) \
    96 )
    97 
    98 /**
    9985 *  This type indicates the direction.
    10086 */
  • cpukit/score/include/rtems/score/scheduleredfimpl.h

    rb767683a r40dcafa  
    9090  RBTree_Node *first = _RBTree_First( &context->Ready, RBT_LEFT );
    9191  Scheduler_EDF_Node *node =
    92     _RBTree_Container_of(first, Scheduler_EDF_Node, Node);
     92    RTEMS_CONTAINER_OF( first, Scheduler_EDF_Node, Node );
    9393  Thread_Control *heir = node->thread;
    9494
  • cpukit/score/include/rtems/score/schedulerimpl.h

    rb767683a r40dcafa  
    165165  Thread_Control *next_needs_help;
    166166  Thread_Control *offers_help =
    167     _Thread_Resource_node_to_thread( resource_node );
     167    THREAD_RESOURCE_NODE_TO_THREAD( resource_node );
    168168  const Scheduler_Control *scheduler = _Scheduler_Get_own( offers_help );
    169169
  • cpukit/score/include/rtems/score/threadimpl.h

    rb767683a r40dcafa  
    7575 */
    7676SCORE_EXTERN struct _reent **_Thread_libc_reent;
     77#endif
     78
     79#define THREAD_RBTREE_NODE_TO_THREAD( node ) \
     80  RTEMS_CONTAINER_OF( node, Thread_Control, RBNode )
     81
     82#if defined(RTEMS_SMP)
     83#define THREAD_RESOURCE_NODE_TO_THREAD( node ) \
     84  RTEMS_CONTAINER_OF( node, Thread_Control, Resource_node )
    7785#endif
    7886
     
    847855}
    848856
    849 #if defined(RTEMS_SMP)
    850 RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Resource_node_to_thread(
    851   Resource_Node *node
    852 )
    853 {
    854   return (Thread_Control *)
    855     ( (char *) node - offsetof( Thread_Control, Resource_node ) );
    856 }
    857 #endif
    858 
    859857RTEMS_INLINE_ROUTINE void _Thread_Debug_set_real_processor(
    860858  Thread_Control  *the_thread,
  • cpukit/score/src/resourceiterate.c

    rb767683a r40dcafa  
    1717static Resource_Control *_Resource_Rival_head_to_resource( Chain_Node *head )
    1818{
    19   return (Resource_Control *)
    20     ( (char *) head - offsetof( Resource_Control, Rivals.Head.Node ) );
     19  return RTEMS_CONTAINER_OF( head, Resource_Control, Rivals.Head.Node );
    2120}
    2221
    2322static Resource_Node *_Resource_Resource_tail_to_rival( Chain_Node *tail )
    2423{
    25   return (Resource_Node *)
    26     ( (char *) tail - offsetof( Resource_Node, Resources.Tail.Node ) );
     24  return RTEMS_CONTAINER_OF( tail, Resource_Node, Resources.Tail.Node );
    2725}
    2826
  • cpukit/score/src/schedulerchangeroot.c

    rb767683a r40dcafa  
    3333  Thread_Control *needs_help = root;
    3434  Thread_Control *offers_help =
    35     _Thread_Resource_node_to_thread( resource_node );
     35    THREAD_RESOURCE_NODE_TO_THREAD( resource_node );
    3636  const Scheduler_Control *scheduler = _Scheduler_Get_own( offers_help );
    3737  Thread_Control *needs_help_too;
  • cpukit/score/src/scheduleredf.c

    rb767683a r40dcafa  
    2626)
    2727{
    28   Priority_Control value1 = _RBTree_Container_of
    29     (n1,Scheduler_EDF_Node,Node)->thread->current_priority;
    30   Priority_Control value2 = _RBTree_Container_of
    31     (n2,Scheduler_EDF_Node,Node)->thread->current_priority;
     28  Scheduler_EDF_Node *edf1 =
     29    RTEMS_CONTAINER_OF( n1, Scheduler_EDF_Node, Node );
     30  Scheduler_EDF_Node *edf2 =
     31    RTEMS_CONTAINER_OF( n2, Scheduler_EDF_Node, Node );
     32  Priority_Control value1 = edf1->thread->current_priority;
     33  Priority_Control value2 = edf2->thread->current_priority;
    3234
    3335  /*
  • cpukit/score/src/threadq.c

    rb767683a r40dcafa  
    2121#include <rtems/score/threadqimpl.h>
    2222#include <rtems/score/chainimpl.h>
     23#include <rtems/score/rbtreeimpl.h>
    2324#include <rtems/score/scheduler.h>
    24 
    25 #include <rtems/score/rbtreeimpl.h>
     25#include <rtems/score/threadimpl.h>
    2626
    2727int _Thread_queue_Compare_priority(
     
    3030)
    3131{
    32   Priority_Control left_priority = _RBTree_Container_of
    33     (left,Thread_Control,RBNode)->current_priority;
    34   Priority_Control right_priority = _RBTree_Container_of
    35     (right,Thread_Control,RBNode)->current_priority;
     32  Priority_Control left_priority =
     33    THREAD_RBTREE_NODE_TO_THREAD( left )->current_priority;
     34  Priority_Control right_priority =
     35    THREAD_RBTREE_NODE_TO_THREAD( right )->current_priority;
    3636
    3737  /*
  • cpukit/score/src/threadqdequeue.c

    rb767683a r40dcafa  
    5151    first = _RBTree_Get( &the_thread_queue->Queues.Priority, RBT_LEFT );
    5252    if ( first ) {
    53       the_thread = _RBTree_Container_of( first, Thread_Control, RBNode );
     53      the_thread = THREAD_RBTREE_NODE_TO_THREAD( first );
    5454    }
    5555  }
  • cpukit/score/src/threadqfirst.c

    rb767683a r40dcafa  
    1919#endif
    2020
     21#include <rtems/score/threadqimpl.h>
    2122#include <rtems/score/chainimpl.h>
    2223#include <rtems/score/isrlevel.h>
    23 #include <rtems/score/threadqimpl.h>
     24#include <rtems/score/threadimpl.h>
    2425
    2526Thread_Control *_Thread_queue_First(
     
    4243    first = _RBTree_First( &the_thread_queue->Queues.Priority, RBT_LEFT );
    4344    if ( first )
    44       thread = _RBTree_Container_of( first, Thread_Control, RBNode );
     45      thread = THREAD_RBTREE_NODE_TO_THREAD( first );
    4546  }
    4647
  • testsuites/sptests/sprbtree01/init.c

    rb767683a r40dcafa  
    3939)
    4040{
    41   int key1 = rtems_rbtree_container_of( n1, test_node, Node )->key;
    42   int key2 = rtems_rbtree_container_of( n2, test_node, Node )->key;
     41  int key1 = RTEMS_CONTAINER_OF( n1, test_node, Node )->key;
     42  int key2 = RTEMS_CONTAINER_OF( n2, test_node, Node )->key;
    4343
    4444  return key1 - key2;
     
    263263  for ( p = rtems_rbtree_get_min(&rbtree1), id = 1 ; p ;
    264264      p = rtems_rbtree_get_min(&rbtree1) , id++ ) {
    265     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     265    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    266266    if ( id > 2 ) {
    267267      puts( "INIT - TOO MANY NODES ON RBTREE" );
     
    291291  for ( p = rtems_rbtree_get_min(&rbtree1), id = 1 ; p ;
    292292      p = rtems_rbtree_get_min(&rbtree1) , id++ ) {
    293     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     293    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    294294    if ( id > 1 ) {
    295295      puts( "INIT - TOO MANY NODES ON RBTREE" );
     
    346346
    347347  puts( "INIT - Verify rtems_rbtree_peek_max/min, rtems_rbtree_extract" );
    348   test_node *t1 = rtems_rbtree_container_of(rtems_rbtree_peek_max(&rbtree1),
     348  test_node *t1 = RTEMS_CONTAINER_OF(rtems_rbtree_peek_max(&rbtree1),
    349349         test_node,Node);
    350   test_node *t2 = rtems_rbtree_container_of(rtems_rbtree_peek_min(&rbtree1),
     350  test_node *t2 = RTEMS_CONTAINER_OF(rtems_rbtree_peek_min(&rbtree1),
    351351         test_node,Node);
    352352  if (t1->key - t2->key != 1) {
     
    356356  p = rtems_rbtree_peek_max(&rbtree1);
    357357  rtems_rbtree_extract(&rbtree1, p);
    358   t1 = rtems_rbtree_container_of(p,test_node,Node);
     358  t1 = RTEMS_CONTAINER_OF(p,test_node,Node);
    359359  if (t1->key != 2) {
    360360    puts( "INIT - rtems_rbtree_extract failed");
     
    366366  for ( p = rtems_rbtree_get_min(&rbtree1), id = 1 ; p ;
    367367      p = rtems_rbtree_get_min(&rbtree1) , id++ ) {
    368     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     368    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    369369    if ( id > 2 ) {
    370370      puts( "INIT - TOO MANY NODES ON RBTREE" );
     
    391391  for ( p = rtems_rbtree_get_min(&rbtree1), id = 0 ; p ;
    392392      p = rtems_rbtree_get_min(&rbtree1) , id++ ) {
    393     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     393    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    394394    if ( id > 99 ) {
    395395      puts( "INIT - TOO MANY NODES ON RBTREE" );
     
    424424  for ( p = rtems_rbtree_get_min(&rbtree1), id = 0 ; p ;
    425425      p = rtems_rbtree_get_min(&rbtree1) , id++ ) {
    426     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     426    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    427427    if ( id > 99 ) {
    428428      puts( "INIT - TOO MANY NODES ON RBTREE" );
     
    468468  for ( p = rtems_rbtree_get_min(&rbtree1), id = 0, i = 0 ; p ;
    469469      p = rtems_rbtree_get_min(&rbtree1) , id++ ) {
    470     test_node *t = rtems_rbtree_container_of(p, test_node, Node);
     470    test_node *t = RTEMS_CONTAINER_OF(p, test_node, Node);
    471471
    472472    while ( id == numbers_sorted[i] ) {
     
    530530  for ( p = rtems_rbtree_get_max(&rbtree1), id = 0 ; p ;
    531531      p = rtems_rbtree_get_max(&rbtree1) , id++ ) {
    532     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     532    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    533533    if ( id > 99 ) {
    534534      puts( "INIT - TOO MANY NODES ON RBTREE" );
     
    562562  search_node.key = 30;
    563563  p = rb_find_unique(&rbtree1, &search_node.Node);
    564   if(rtems_rbtree_container_of(p,test_node,Node)->id != 30) {
     564  if(RTEMS_CONTAINER_OF(p,test_node,Node)->id != 30) {
    565565    puts ("INIT - ERROR ON RBTREE ID MISMATCH");
    566566    rtems_test_exit(0);
     
    569569  puts( "INIT - Verify rtems_rbtree_predecessor/successor");
    570570  p = rtems_rbtree_predecessor(p);
    571   if(p && rtems_rbtree_container_of(p,test_node,Node)->id != 29) {
     571  if(p && RTEMS_CONTAINER_OF(p,test_node,Node)->id != 29) {
    572572    puts ("INIT - ERROR ON RBTREE ID MISMATCH");
    573573    rtems_test_exit(0);
     
    575575  p = rb_find_unique(&rbtree1, &search_node.Node);
    576576  p = rtems_rbtree_successor(p);
    577   if(p && rtems_rbtree_container_of(p,test_node,Node)->id != 31) {
     577  if(p && RTEMS_CONTAINER_OF(p,test_node,Node)->id != 31) {
    578578    puts ("INIT - ERROR ON RBTREE ID MISMATCH");
    579579    rtems_test_exit(0);
     
    602602  for ( p = rtems_rbtree_get_max(&rbtree1), id = 99 ; p ;
    603603      p = rtems_rbtree_get_max(&rbtree1) , id-- ) {
    604     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     604    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    605605    if ( id < 0 ) {
    606606      puts( "INIT - TOO MANY NODES ON RBTREE" );
     
    635635  for ( p = rtems_rbtree_get_min(&rbtree1), id = 0 ; p ;
    636636      p = rtems_rbtree_get_min(&rbtree1) , id++ ) {
    637     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     637    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    638638    if ( id > 19 ) {
    639639      puts( "INIT - TOO MANY NODES ON RBTREE" );
     
    667667  for ( p = rtems_rbtree_get_min(&rbtree1), id = 0 ; p ;
    668668      p = rtems_rbtree_get_min(&rbtree1) , id++ ) {
    669     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     669    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    670670    if ( id > 99 ) {
    671671      puts( "INIT - TOO MANY NODES ON RBTREE" );
     
    704704  search_node.key = 2;
    705705  p = rb_find_multi(&rbtree1, &search_node.Node);
    706   if(rtems_rbtree_container_of(p,test_node,Node)->id != 2) {
     706  if(RTEMS_CONTAINER_OF(p,test_node,Node)->id != 2) {
    707707    puts ("INIT - ERROR ON RBTREE ID MISMATCH");
    708708    rtems_test_exit(0);
     
    713713  for ( p = rtems_rbtree_get_min(&rbtree1), id = 0 ; p ;
    714714      p = rtems_rbtree_get_min(&rbtree1) , id++ ) {
    715     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     715    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    716716    if ( id > 99 ) {
    717717      puts( "INIT - TOO MANY NODES ON RBTREE" );
     
    745745  search_node.key = 2;
    746746  p = rb_find_multi(&rbtree1, &search_node.Node);
    747   if(rtems_rbtree_container_of(p,test_node,Node)->id != 97) {
     747  if(RTEMS_CONTAINER_OF(p,test_node,Node)->id != 97) {
    748748    puts ("INIT - ERROR ON RBTREE ID MISMATCH");
    749749    rtems_test_exit(0);
     
    754754  for ( p = rtems_rbtree_get_min(&rbtree1), id = 0 ; p ;
    755755      p = rtems_rbtree_get_min(&rbtree1) , id++ ) {
    756     test_node *t = rtems_rbtree_container_of(p,test_node,Node);
     756    test_node *t = RTEMS_CONTAINER_OF(p,test_node,Node);
    757757    if ( id > 99 ) {
    758758      puts( "INIT - TOO MANY NODES ON RBTREE" );
Note: See TracChangeset for help on using the changeset viewer.