source: rtems/cpukit/posix/include/rtems/posix/keyimpl.h @ 390cfcd

4.115
Last change on this file since 390cfcd was 390cfcd, checked in by Sebastian Huber <sebastian.huber@…>, on 08/02/14 at 13:49:26

posix: Simplify key implementation

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Private Inlined Routines for POSIX Key's
5 *
6 * This include file contains the static inline implementation of the private
7 * inlined routines for POSIX key's.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-1999.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#include <rtems/posix/key.h>
20#include <rtems/score/freechain.h>
21#include <rtems/score/objectimpl.h>
22#include <rtems/score/percpu.h>
23
24#ifndef _RTEMS_POSIX_KEYIMPL_H
25#define _RTEMS_POSIX_KEYIMPL_H
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * @addtogroup POSIX_KEY
33 *
34 * @{
35 */
36
37/**
38 * @brief The information control block used to manage this class of objects.
39 */
40POSIX_EXTERN Objects_Information  _POSIX_Keys_Information;
41
42/**
43 * @brief The rbtree control block used to manage all key values
44 */
45extern RBTree_Control _POSIX_Keys_Key_value_lookup_tree;
46
47/**
48 * @brief This freechain is used as a memory pool for POSIX_Keys_Key_value_pair.
49 */
50POSIX_EXTERN Freechain_Control _POSIX_Keys_Keypool;
51
52#define POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ) \
53  RTEMS_CONTAINER_OF( node, POSIX_Keys_Key_value_pair, Key_value_lookup_node )
54
55/**
56 * @brief POSIX key manager initialization.
57 *
58 * This routine performs the initialization necessary for this manager.
59 */
60void _POSIX_Key_Manager_initialization(void);
61
62/**
63 * @brief POSIX keys Red-Black tree node comparison.
64 *
65 * This routine compares the rbtree node
66 */
67RBTree_Compare_result _POSIX_Keys_Key_value_compare(
68  const RBTree_Node *node1,
69  const RBTree_Node *node2
70);
71
72/**
73 * @brief Create thread-specific data POSIX key.
74 *
75 * This function executes all the destructors associated with the thread's
76 * keys.  This function will execute until all values have been set to NULL.
77 *
78 * @param[in] thread is a pointer to the thread whose keys should have
79 *            all their destructors run.
80 *
81 * NOTE: This is the routine executed when a thread exits to
82 *       run through all the keys and do the destructor action.
83 */
84void _POSIX_Keys_Run_destructors(
85  Thread_Control *thread
86);
87
88/**
89 * @brief Free a POSIX key table memory.
90 *
91 * This memory frees the key table memory associated with @a the_key.
92 *
93 * @param[in] the_key is a pointer to the POSIX key to free
94 * the table memory of.
95 */
96void _POSIX_Keys_Free_memory(
97  POSIX_Keys_Control *the_key
98);
99
100/**
101 * @brief Free a POSIX keys control block.
102 *
103 * This routine frees a keys control block to the
104 * inactive chain of free keys control blocks.
105 *
106 * @param[in] the_key is a pointer to the POSIX key to free.
107 */
108RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free (
109  POSIX_Keys_Control *the_key
110);
111
112/**
113 * @brief Allocate a keys control block.
114 *
115 * This function allocates a keys control block from
116 * the inactive chain of free keys control blocks.
117 */
118
119RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Allocate( void )
120{
121  return (POSIX_Keys_Control *) _Objects_Allocate( &_POSIX_Keys_Information );
122}
123
124/**
125 * @brief Free a keys control block.
126 *
127 * This routine frees a keys control block to the
128 * inactive chain of free keys control blocks.
129 */
130RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free (
131  POSIX_Keys_Control *the_key
132)
133{
134  _Objects_Free( &_POSIX_Keys_Information, &the_key->Object );
135}
136
137/**
138 * @brief Get a keys control block.
139 *
140 * This function maps key IDs to key control blocks.
141 * If ID corresponds to a local keys, then it returns
142 * the_key control pointer which maps to ID and location
143 * is set to OBJECTS_LOCAL.  if the keys ID is global and
144 * resides on a remote node, then location is set to OBJECTS_REMOTE,
145 * and the_key is undefined.  Otherwise, location is set
146 * to OBJECTS_ERROR and the_key is undefined.
147 */
148
149RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Get (
150  pthread_key_t      id,
151  Objects_Locations *location
152)
153{
154  return (POSIX_Keys_Control *)
155    _Objects_Get( &_POSIX_Keys_Information, (Objects_Id) id, location );
156}
157
158RTEMS_INLINE_ROUTINE POSIX_Keys_Key_value_pair *
159_POSIX_Keys_Key_value_pair_allocate( void )
160{
161  return (POSIX_Keys_Key_value_pair *) _Freechain_Get( &_POSIX_Keys_Keypool );
162}
163
164RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_pair_free(
165  POSIX_Keys_Key_value_pair *key_value_pair
166)
167{
168  _Freechain_Put( &_POSIX_Keys_Keypool, key_value_pair );
169}
170
171RTEMS_INLINE_ROUTINE RBTree_Node *_POSIX_Keys_Find(
172  pthread_key_t              key,
173  Thread_Control            *thread,
174  POSIX_Keys_Key_value_pair *search_node
175)
176{
177  search_node->key = key;
178  search_node->thread = thread;
179
180  return _RBTree_Find(
181    &_POSIX_Keys_Key_value_lookup_tree,
182    &search_node->Key_value_lookup_node,
183    _POSIX_Keys_Key_value_compare,
184    true
185  );
186}
187
188/** @} */
189
190#ifdef __cplusplus
191}
192#endif
193
194#endif
195/*  end of include file */
Note: See TracBrowser for help on using the repository browser.