Changeset 390cfcd in rtems


Ignore:
Timestamp:
08/02/14 13:49:26 (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
888edf6
Parents:
60fe374
git-author:
Sebastian Huber <sebastian.huber@…> (08/02/14 13:49:26)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/05/14 07:30:37)
Message:

posix: Simplify key implementation

Location:
cpukit/posix
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/include/rtems/posix/key.h

    r60fe374 r390cfcd  
    2626#include <rtems/score/object.h>
    2727#include <rtems/score/rbtree.h>
     28#include <rtems/score/thread.h>
    2829
    2930#ifdef __cplusplus
     
    4041
    4142/**
    42  * @brief The rbtree node used to manage a POSIX key and value.
     43 * @brief Represents POSIX key and value pair.
    4344 */
    4445typedef struct {
    45   /** This field is the chain node structure. */
     46  /**
     47   * @brief The chain node for the per-thread value chain.
     48   */
    4649  Chain_Node Key_values_per_thread_node;
    47   /** This field is the rbtree node structure. */
     50
     51  /**
     52   * @brief The tree node for the lookup tree.
     53   */
    4854  RBTree_Node Key_value_lookup_node;
    49   /** This field is the POSIX key used as an rbtree key */
     55
     56  /**
     57   * @brief The POSIX key identifier used in combination with the thread
     58   * pointer as the tree key.
     59   */
    5060  pthread_key_t key;
    51   /** This field is the Thread id also used as an rbtree key */
    52   Objects_Id thread_id;
    53   /** This field points to the POSIX key value of specific thread */
     61
     62  /**
     63   * @brief The thread pointer used in combination with the POSIX key
     64   * identifier as the tree key.
     65   */
     66  Thread_Control *thread;
     67
     68  /**
     69   * @brief The thread specific POSIX key value.
     70   */
    5471  const void *value;
    55 }  POSIX_Keys_Key_value_pair;
     72} POSIX_Keys_Key_value_pair;
    5673
    5774/**
  • cpukit/posix/include/rtems/posix/keyimpl.h

    r60fe374 r390cfcd  
    171171RTEMS_INLINE_ROUTINE RBTree_Node *_POSIX_Keys_Find(
    172172  pthread_key_t              key,
    173   Objects_Id                 thread_id,
     173  Thread_Control            *thread,
    174174  POSIX_Keys_Key_value_pair *search_node
    175175)
    176176{
    177177  search_node->key = key;
    178   search_node->thread_id = thread_id;
     178  search_node->thread = thread;
    179179
    180180  return _RBTree_Find(
  • cpukit/posix/src/key.c

    r60fe374 r390cfcd  
    5252  POSIX_Keys_Key_value_pair *n1;
    5353  POSIX_Keys_Key_value_pair *n2;
    54   Objects_Id thread_id1, thread_id2;
     54  Thread_Control *thread1;
     55  Thread_Control *thread2;
    5556  RBTree_Compare_result diff;
    5657
     
    6263    return diff;
    6364
    64   thread_id1 = n1->thread_id;
    65   thread_id2 = n2->thread_id;
     65  thread1 = n1->thread;
     66  thread2 = n2->thread;
    6667
    67   /**
    68    * if thread_id1 or thread_id2 equals to 0, only key1 and key2 is valued.
    69    * it enables us search node only by pthread_key_t type key.
     68  /*
     69   * If thread1 or thread2 equals to NULL, only key1 and key2 is valued.  It
     70   * enables us search node only by pthread_key_t type key.  Exploit that the
     71   * thread control alignment is at least two to avoid integer overflows.
    7072   */
    71   if ( thread_id1 && thread_id2 )
    72     return thread_id1 - thread_id2;
     73  if ( thread1 != NULL && thread2 != NULL )
     74    return (RBTree_Compare_result) ( (uintptr_t) thread1 >> 1 )
     75      - (RBTree_Compare_result) ( (uintptr_t) thread2 >> 1 );
     76
    7377  return 0;
    7478}
  • cpukit/posix/src/keygetspecific.c

    r60fe374 r390cfcd  
    5050
    5151    case OBJECTS_LOCAL:
    52       p = _POSIX_Keys_Find( key, _Thread_Executing->Object.id, &search_node );
     52      p = _POSIX_Keys_Find( key, _Thread_Executing, &search_node );
    5353      if ( p != NULL ) {
    5454        value_pair_p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( p );
  • cpukit/posix/src/keysetspecific.c

    r60fe374 r390cfcd  
    4040  RBTree_Node                 *p;
    4141  POSIX_Keys_Key_value_pair    search_node;
     42  Thread_Control              *executing;
    4243
    4344  the_key = _POSIX_Keys_Get( key, &location );
     
    4546
    4647    case OBJECTS_LOCAL:
    47       p = _POSIX_Keys_Find( key, _Thread_Executing->Object.id, &search_node );
     48      executing = _Thread_Executing;
     49      p = _POSIX_Keys_Find( key, executing, &search_node );
    4850      if ( p != NULL ) {
    4951        value_pair_ptr = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( p );
     
    5961
    6062        value_pair_ptr->key = key;
    61         value_pair_ptr->thread_id = _Thread_Executing->Object.id;
     63        value_pair_ptr->thread = executing;
    6264        value_pair_ptr->value = value;
    6365        /* The insert can only go wrong if the same node is already in a unique
Note: See TracChangeset for help on using the changeset viewer.