From 5eaf0e7458bac80ba669f03c4feaae5bad55c6c9 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Mar 2016 07:56:31 +0100 Subject: posix: Use per-thread lookup tree for POSIX Keys Yields higher performance on SMP systems. Close #2625. --- cpukit/posix/src/keygetspecific.c | 50 +++++++++++++-------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) (limited to 'cpukit/posix/src/keygetspecific.c') diff --git a/cpukit/posix/src/keygetspecific.c b/cpukit/posix/src/keygetspecific.c index ef6c19d56c..08ac1ed28c 100644 --- a/cpukit/posix/src/keygetspecific.c +++ b/cpukit/posix/src/keygetspecific.c @@ -9,6 +9,7 @@ * Copyright (c) 2012 Zhongwei Yao. * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). + * Copyright (c) 2016 embedded brains GmbH. * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -19,15 +20,6 @@ #include "config.h" #endif -#include -#include -#include -#include - -#include -#include -#include -#include #include /* @@ -38,34 +30,26 @@ void *pthread_getspecific( pthread_key_t key ) { - POSIX_Keys_Control *the_key; - Objects_Locations location; - RBTree_Node *p; - void *key_data; - POSIX_Keys_Key_value_pair *value_pair_p; - - the_key = _POSIX_Keys_Get( key, &location ); - switch ( location ) { + Thread_Control *executing; + ISR_lock_Context lock_context; + RBTree_Node *node; + void *value; - case OBJECTS_LOCAL: - p = _POSIX_Keys_Find( key, _Thread_Executing ); - 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; - } + executing = _Thread_Get_executing(); + _POSIX_Keys_Key_value_acquire( executing, &lock_context ); - _Objects_Put( &the_key->Object ); + node = _POSIX_Keys_Key_value_find( key, executing ); - return key_data; + if ( node != NULL ) { + POSIX_Keys_Key_value_pair *key_value_pair; -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: /* should never happen */ -#endif - case OBJECTS_ERROR: - break; + key_value_pair = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ); + value = key_value_pair->value; + } else { + value = NULL; } - return NULL; + _POSIX_Keys_Key_value_release( executing, &lock_context ); + + return value; } -- cgit v1.2.3