static int _POSIX_Keys_Set_value( pthread_key_t key, const void *value, POSIX_Keys_Control *the_key, Thread_Control *executing, RBTree_Node *rb_node ) { POSIX_Keys_Key_value_pair *key_value_pair; if ( rb_node != NULL ) { key_value_pair = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( rb_node ); key_value_pair->value = RTEMS_DECONST( void *, value ); } else {
void _POSIX_Keys_Free_memory( POSIX_Keys_Control *the_key ) { POSIX_Keys_Key_value_pair *p; RBTree_Node *iter, *next; Objects_Id key_id; key_id = the_key->Object.id; iter = _POSIX_Keys_Find( key_id, 0 ); if ( !iter ) return; /** * find the smallest thread_id node in the rbtree. */ next = _RBTree_Next( iter, RBT_LEFT ); p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( next ); while ( next != NULL && p->key == key_id) { iter = next; next = _RBTree_Next( iter, RBT_LEFT ); p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( next ); } /** * delete all nodes belongs to the_key from the rbtree and chain. */ p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( iter ); while ( iter != NULL && p->key == key_id ) { next = _RBTree_Next( iter, RBT_RIGHT ); _POSIX_Keys_Free_key_value_pair( p ); iter = next; p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( iter ); } }
int pthread_setspecific( pthread_key_t key, const void *value ) { POSIX_Keys_Control *the_key; Objects_Locations location; POSIX_Keys_Key_value_pair *value_pair_ptr; RBTree_Node *p; POSIX_Keys_Key_value_pair search_node; Thread_Control *executing; the_key = _POSIX_Keys_Get( key, &location ); switch ( location ) { case OBJECTS_LOCAL: executing = _Thread_Executing; p = _POSIX_Keys_Find( key, executing, &search_node ); if ( p != NULL ) { value_pair_ptr = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( p ); value_pair_ptr->value = RTEMS_DECONST( void *, value ); } else {
void *pthread_getspecific( pthread_key_t key ) { POSIX_Keys_Control *the_key; Objects_Locations location; POSIX_Keys_Key_value_pair search_node; RBTree_Node *p; void *key_data; POSIX_Keys_Key_value_pair *value_pair_p; the_key = _POSIX_Keys_Get( key, &location ); switch ( location ) { case OBJECTS_LOCAL: p = _POSIX_Keys_Find( key, _Thread_Executing, &search_node ); if ( p != NULL ) { value_pair_p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( p ); key_data = value_pair_p->value; } else { key_data = NULL; } _Objects_Put( &the_key->Object ); return key_data; #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: /* should never happen */ #endif case OBJECTS_ERROR: break; } return NULL; }
int pthread_setspecific( pthread_key_t key, const void *value ) { POSIX_Keys_Control *the_key; Objects_Locations location; POSIX_Keys_Key_value_pair *value_pair_ptr; RBTree_Node *p; POSIX_Keys_Key_value_pair search_node; Thread_Control *executing; the_key = _POSIX_Keys_Get( key, &location ); switch ( location ) { case OBJECTS_LOCAL: executing = _Thread_Executing; p = _POSIX_Keys_Find( key, executing, &search_node ); if ( p != NULL ) { value_pair_ptr = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( p ); value_pair_ptr->value = value; } else { value_pair_ptr = _POSIX_Keys_Key_value_pair_allocate(); if ( !value_pair_ptr ) { _Objects_Put( &the_key->Object ); return ENOMEM; } value_pair_ptr->key = key; value_pair_ptr->thread = executing; value_pair_ptr->value = value; /* The insert can only go wrong if the same node is already in a unique * tree. This has been already checked with the _RBTree_Find() */ _RBTree_Insert( &_POSIX_Keys_Key_value_lookup_tree, &value_pair_ptr->Key_value_lookup_node, _POSIX_Keys_Key_value_compare, true ); /** append rb_node to the thread API extension's chain */ _Chain_Append_unprotected( &_Thread_Executing->Key_Chain, &value_pair_ptr->Key_values_per_thread_node ); } _Objects_Put( &the_key->Object ); return 0; #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: /* should never happen */ #endif case OBJECTS_ERROR: break; } return EINVAL; }