From 2605a48938b9b3466add326d8e94b9622ffad7ba Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 15 Dec 2015 09:32:55 +0100 Subject: Optional POSIX Keys initialization Update #2408. --- cpukit/posix/Makefile.am | 2 +- cpukit/posix/include/rtems/posix/keyimpl.h | 27 +--------- cpukit/posix/src/key.c | 69 +++++++++++++++++++++++- cpukit/posix/src/keyrundestructors.c | 84 ------------------------------ 4 files changed, 71 insertions(+), 111 deletions(-) delete mode 100644 cpukit/posix/src/keyrundestructors.c (limited to 'cpukit/posix') diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am index 54a298aaeb..40bc15339d 100644 --- a/cpukit/posix/Makefile.am +++ b/cpukit/posix/Makefile.am @@ -154,7 +154,7 @@ endif ## KEY_C_FILES libposix_a_SOURCES += src/key.c src/keycreate.c src/keydelete.c \ - src/keygetspecific.c src/keyfreememory.c src/keyrundestructors.c \ + src/keygetspecific.c src/keyfreememory.c \ src/keysetspecific.c ## ONCE_C_FILES diff --git a/cpukit/posix/include/rtems/posix/keyimpl.h b/cpukit/posix/include/rtems/posix/keyimpl.h index 6fd4d1348a..1addb1e376 100644 --- a/cpukit/posix/include/rtems/posix/keyimpl.h +++ b/cpukit/posix/include/rtems/posix/keyimpl.h @@ -38,7 +38,7 @@ extern "C" { /** * @brief The information control block used to manage this class of objects. */ -POSIX_EXTERN Objects_Information _POSIX_Keys_Information; +extern Objects_Information _POSIX_Keys_Information; /** * @brief The rbtree control block used to manage all key values @@ -48,18 +48,11 @@ extern RBTree_Control _POSIX_Keys_Key_value_lookup_tree; /** * @brief This freechain is used as a memory pool for POSIX_Keys_Key_value_pair. */ -POSIX_EXTERN Freechain_Control _POSIX_Keys_Keypool; +extern Freechain_Control _POSIX_Keys_Keypool; #define POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ) \ RTEMS_CONTAINER_OF( node, POSIX_Keys_Key_value_pair, Key_value_lookup_node ) -/** - * @brief POSIX key manager initialization. - * - * This routine performs the initialization necessary for this manager. - */ -void _POSIX_Key_Manager_initialization(void); - /** * @brief POSIX keys Red-Black tree node comparison. * @@ -70,22 +63,6 @@ RBTree_Compare_result _POSIX_Keys_Key_value_compare( const RBTree_Node *node2 ); -/** - * @brief Create thread-specific data POSIX key. - * - * This function executes all the destructors associated with the thread's - * keys. This function will execute until all values have been set to NULL. - * - * @param[in] thread is a pointer to the thread whose keys should have - * all their destructors run. - * - * NOTE: This is the routine executed when a thread exits to - * run through all the keys and do the destructor action. - */ -void _POSIX_Keys_Run_destructors( - Thread_Control *thread -); - /** * @brief Free a POSIX key table memory. * diff --git a/cpukit/posix/src/key.c b/cpukit/posix/src/key.c index 55c6590051..5a0886b980 100644 --- a/cpukit/posix/src/key.c +++ b/cpukit/posix/src/key.c @@ -20,14 +20,20 @@ #endif #include +#include #include #include #include +#include #include +Objects_Information _POSIX_Keys_Information; + RBTREE_DEFINE_EMPTY( _POSIX_Keys_Key_value_lookup_tree ); +Freechain_Control _POSIX_Keys_Keypool; + /** * @brief This routine compares the rbtree node by comparing POSIX key first * and comparing thread id second. @@ -112,10 +118,63 @@ POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_pair_allocate( void ) ); } +static void _POSIX_Keys_Run_destructors( Thread_Control *thread ) +{ + Chain_Control *chain; + POSIX_Keys_Key_value_pair *iter, *next; + void *value; + void (*destructor) (void *); + POSIX_Keys_Control *the_key; + Objects_Locations location; + + chain = &thread->Key_Chain; + iter = (POSIX_Keys_Key_value_pair *) _Chain_First( chain ); + while ( !_Chain_Is_tail( chain, &iter->Key_values_per_thread_node ) ) { + next = (POSIX_Keys_Key_value_pair *) + _Chain_Next( &iter->Key_values_per_thread_node ); + + the_key = _POSIX_Keys_Get( iter->key, &location ); + _Assert( location == OBJECTS_LOCAL ); + + /** + * remove key from rbtree and chain. + * here Chain_Node *iter can be convert to POSIX_Keys_Key_value_pair *, + * because Chain_Node is the first member of POSIX_Keys_Key_value_pair + * structure. + */ + _RBTree_Extract( + &_POSIX_Keys_Key_value_lookup_tree, + &iter->Key_value_lookup_node + ); + _Chain_Extract_unprotected( &iter->Key_values_per_thread_node ); + + destructor = the_key->destructor; + value = iter->value; + + _POSIX_Keys_Key_value_pair_free( iter ); + + _Objects_Put( &the_key->Object ); + + /** + * run key value's destructor if destructor and value are both non-null. + */ + if ( destructor != NULL && value != NULL ) + (*destructor)( value ); + + iter = next; + } +} + +static User_extensions_Control _POSIX_Keys_Extensions = { + .Callouts = { + .thread_terminate = _POSIX_Keys_Run_destructors + } +}; + /** * @brief This routine performs the initialization necessary for this manager. */ -void _POSIX_Key_Manager_initialization(void) +static void _POSIX_Keys_Manager_initialization(void) { _Objects_Initialize_information( &_POSIX_Keys_Information, /* object information table */ @@ -135,4 +194,12 @@ void _POSIX_Key_Manager_initialization(void) ); _POSIX_Keys_Initialize_keypool(); + + _User_extensions_Add_API_set( &_POSIX_Keys_Extensions ); } + +RTEMS_SYSINIT_ITEM( + _POSIX_Keys_Manager_initialization, + RTEMS_SYSINIT_POSIX_KEYS, + RTEMS_SYSINIT_ORDER_MIDDLE +); diff --git a/cpukit/posix/src/keyrundestructors.c b/cpukit/posix/src/keyrundestructors.c deleted file mode 100644 index 96147a539d..0000000000 --- a/cpukit/posix/src/keyrundestructors.c +++ /dev/null @@ -1,84 +0,0 @@ -/** - * @file - * - * @brief Thread-Specific Data Key Create - * @ingroup POSIX_KEY Key - */ - -/* - * Copyright (c) 2012 Zhongwei Yao. - * Copyright (c) 2010-2014 embedded brains GmbH. - * - * COPYRIGHT (c) 1989-2014. - * 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.org/license/LICENSE. - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -/* - * _POSIX_Keys_Run_destructors - * - * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 - * - * NOTE: This is the routine executed when a thread exits to - * run through all the keys and do the destructor action. - */ -void _POSIX_Keys_Run_destructors( - Thread_Control *thread -) -{ - Chain_Control *chain; - POSIX_Keys_Key_value_pair *iter, *next; - void *value; - void (*destructor) (void *); - POSIX_Keys_Control *the_key; - Objects_Locations location; - - chain = &thread->Key_Chain; - iter = (POSIX_Keys_Key_value_pair *) _Chain_First( chain ); - while ( !_Chain_Is_tail( chain, &iter->Key_values_per_thread_node ) ) { - next = (POSIX_Keys_Key_value_pair *) - _Chain_Next( &iter->Key_values_per_thread_node ); - - the_key = _POSIX_Keys_Get( iter->key, &location ); - _Assert( location == OBJECTS_LOCAL ); - - /** - * remove key from rbtree and chain. - * here Chain_Node *iter can be convert to POSIX_Keys_Key_value_pair *, - * because Chain_Node is the first member of POSIX_Keys_Key_value_pair - * structure. - */ - _RBTree_Extract( - &_POSIX_Keys_Key_value_lookup_tree, - &iter->Key_value_lookup_node - ); - _Chain_Extract_unprotected( &iter->Key_values_per_thread_node ); - - destructor = the_key->destructor; - value = iter->value; - - _POSIX_Keys_Key_value_pair_free( iter ); - - _Objects_Put( &the_key->Object ); - - /** - * run key value's destructor if destructor and value are both non-null. - */ - if ( destructor != NULL && value != NULL ) - (*destructor)( value ); - - iter = next; - } -} -- cgit v1.2.3