summaryrefslogtreecommitdiffstats
path: root/cpukit/posix
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2015-12-15 09:32:55 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-02-03 10:00:56 +0100
commit2605a48938b9b3466add326d8e94b9622ffad7ba (patch)
treee9a9a7600bcd5a187c76c8a0320a8361207e6517 /cpukit/posix
parentOptional CPU Set Handler initialization (diff)
downloadrtems-2605a48938b9b3466add326d8e94b9622ffad7ba.tar.bz2
Optional POSIX Keys initialization
Update #2408.
Diffstat (limited to 'cpukit/posix')
-rw-r--r--cpukit/posix/Makefile.am2
-rw-r--r--cpukit/posix/include/rtems/posix/keyimpl.h27
-rw-r--r--cpukit/posix/src/key.c69
-rw-r--r--cpukit/posix/src/keyrundestructors.c84
4 files changed, 71 insertions, 111 deletions
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,19 +48,12 @@ 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.
*
* This routine compares the rbtree node
@@ -71,22 +64,6 @@ RBTree_Compare_result _POSIX_Keys_Key_value_compare(
);
/**
- * @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.
*
* This memory frees the key table memory associated with @a the_key.
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 <rtems/config.h>
+#include <rtems/sysinit.h>
#include <rtems/posix/keyimpl.h>
#include <rtems/score/chainimpl.h>
#include <rtems/score/objectimpl.h>
+#include <rtems/score/userextimpl.h>
#include <rtems/score/wkspace.h>
+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 <rtems/posix/keyimpl.h>
-#include <rtems/score/assert.h>
-#include <rtems/score/chainimpl.h>
-#include <rtems/score/thread.h>
-
-/*
- * _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;
- }
-}