diff options
author | Zhongwei Yao <ashi08104@gmail.com> | 2013-08-05 09:20:45 -0400 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-08-06 14:11:38 +0200 |
commit | b5c906429f6e67452eec1b0089ac7a204ff998ee (patch) | |
tree | 5e24aed5499922f6d3fa6e1559f5bc7e83fba4b2 /cpukit/posix/src/keysetspecific.c | |
parent | bsp/realview-pbx-a9: Enable fast idle clock (diff) | |
download | rtems-b5c906429f6e67452eec1b0089ac7a204ff998ee.tar.bz2 |
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.
Diffstat (limited to 'cpukit/posix/src/keysetspecific.c')
-rw-r--r-- | cpukit/posix/src/keysetspecific.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/cpukit/posix/src/keysetspecific.c b/cpukit/posix/src/keysetspecific.c index 22eb8eb643..f527fe1ee4 100644 --- a/cpukit/posix/src/keysetspecific.c +++ b/cpukit/posix/src/keysetspecific.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 @@ -22,11 +23,14 @@ #include <limits.h> #include <pthread.h> #include <string.h> +#include <stddef.h> #include <rtems/system.h> #include <rtems/score/thread.h> #include <rtems/score/wkspace.h> +#include <rtems/score/rbtree.h> #include <rtems/posix/key.h> +#include <rtems/posix/threadsup.h> /* * 17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165 @@ -37,19 +41,38 @@ int pthread_setspecific( const void *value ) { - register POSIX_Keys_Control *the_key; - uint32_t api; - uint32_t index; Objects_Locations location; + POSIX_Keys_Key_value_pair *value_pair_ptr; + POSIX_API_Control *api; - 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 ); - the_key->Values[ api ][ index ] = (void *) value; - _Objects_Put( &the_key->Object ); + value_pair_ptr = ( POSIX_Keys_Key_value_pair * ) + _Freechain_Get( &_POSIX_Keys_Keypool.super_fc ); + if ( !value_pair_ptr ) { + _Thread_Enable_dispatch(); + return ENOMEM; + } + + value_pair_ptr->key = key; + value_pair_ptr->thread_id = _Thread_Executing->Object.id; + value_pair_ptr->value = value; + if ( _RBTree_Insert_unprotected( &_POSIX_Keys_Key_value_lookup_tree, + &(value_pair_ptr->Key_value_lookup_node) ) ) { + _Freechain_Put( (Freechain_Control *)&_POSIX_Keys_Keypool, + (void *) value_pair_ptr ); + _Thread_Enable_dispatch(); + return EAGAIN; + } + + /** append rb_node to the thread API extension's chain */ + api = (POSIX_API_Control *)\ + (_Thread_Executing->API_Extensions[THREAD_API_POSIX]); + _Chain_Append_unprotected( &api->Key_Chain, &value_pair_ptr->Key_values_per_thread_node ); + + _Thread_Enable_dispatch(); return 0; #if defined(RTEMS_MULTIPROCESSING) |