From b5c906429f6e67452eec1b0089ac7a204ff998ee Mon Sep 17 00:00:00 2001 From: Zhongwei Yao Date: Mon, 5 Aug 2013 09:20:45 -0400 Subject: Unlimited objects support for POSIX keys This patch enables unlimited model in POSIX key manger and have a decent runtime on POSIX key searching, adding and deleting operations. Memory overhead is lower than current implementation when the size of key and key value becomes big. --- cpukit/posix/src/keygetspecific.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'cpukit/posix/src/keygetspecific.c') diff --git a/cpukit/posix/src/keygetspecific.c b/cpukit/posix/src/keygetspecific.c index 0e8bbcdec8..88e084ee96 100644 --- a/cpukit/posix/src/keygetspecific.c +++ b/cpukit/posix/src/keygetspecific.c @@ -6,12 +6,13 @@ */ /* - * COPYRIGHT (c) 1989-2007. - * On-Line Applications Research Corporation (OAR). + * Copyright (c) 2012 Zhongwei Yao. + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.com/license/LICENSE. + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. */ #if HAVE_CONFIG_H @@ -26,6 +27,7 @@ #include #include #include +#include #include /* @@ -36,20 +38,31 @@ void *pthread_getspecific( pthread_key_t key ) { - register POSIX_Keys_Control *the_key; - uint32_t api; - uint32_t index; 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 ); + _POSIX_Keys_Get( key, &location ); switch ( location ) { case OBJECTS_LOCAL: - api = _Objects_Get_API( _Thread_Executing->Object.id ); - index = _Objects_Get_index( _Thread_Executing->Object.id ); - key_data = (void *) the_key->Values[ api ][ index ]; - _Objects_Put( &the_key->Object ); + search_node.key = key; + search_node.thread_id = _Thread_Executing->Object.id; + p = _RBTree_Find_unprotected( &_POSIX_Keys_Key_value_lookup_tree, + &search_node.Key_value_lookup_node ); + key_data = NULL; + if ( p ) { + value_pair_p = _RBTree_Container_of( p, + POSIX_Keys_Key_value_pair, + Key_value_lookup_node ); + /* key_data = _RBTree_Container_of( p, */ + /* POSIX_Keys_Key_value_pair, */ + /* Key_value_lookup_node )->value; */ + key_data = value_pair_p->value; + } + _Thread_Enable_dispatch(); return key_data; #if defined(RTEMS_MULTIPROCESSING) -- cgit v1.2.3