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/chainimpl.h> |
---|
21 | #include <rtems/score/freechain.h> |
---|
22 | #include <rtems/score/objectimpl.h> |
---|
23 | #include <rtems/score/percpu.h> |
---|
24 | |
---|
25 | #ifndef _RTEMS_POSIX_KEYIMPL_H |
---|
26 | #define _RTEMS_POSIX_KEYIMPL_H |
---|
27 | |
---|
28 | #ifdef __cplusplus |
---|
29 | extern "C" { |
---|
30 | #endif |
---|
31 | |
---|
32 | /** |
---|
33 | * @addtogroup POSIX_KEY |
---|
34 | * |
---|
35 | * @{ |
---|
36 | */ |
---|
37 | |
---|
38 | /** |
---|
39 | * @brief The information control block used to manage this class of objects. |
---|
40 | */ |
---|
41 | extern Objects_Information _POSIX_Keys_Information; |
---|
42 | |
---|
43 | /** |
---|
44 | * @brief The rbtree control block used to manage all key values |
---|
45 | */ |
---|
46 | extern RBTree_Control _POSIX_Keys_Key_value_lookup_tree; |
---|
47 | |
---|
48 | /** |
---|
49 | * @brief This freechain is used as a memory pool for POSIX_Keys_Key_value_pair. |
---|
50 | */ |
---|
51 | extern Freechain_Control _POSIX_Keys_Keypool; |
---|
52 | |
---|
53 | #define POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ) \ |
---|
54 | RTEMS_CONTAINER_OF( node, POSIX_Keys_Key_value_pair, Key_value_lookup_node ) |
---|
55 | |
---|
56 | /** |
---|
57 | * @brief POSIX keys Red-Black tree node comparison. |
---|
58 | * |
---|
59 | * This routine compares the rbtree node |
---|
60 | */ |
---|
61 | RBTree_Compare_result _POSIX_Keys_Key_value_compare( |
---|
62 | const RBTree_Node *node1, |
---|
63 | const RBTree_Node *node2 |
---|
64 | ); |
---|
65 | |
---|
66 | /** |
---|
67 | * @brief Free a POSIX key table memory. |
---|
68 | * |
---|
69 | * This memory frees the key table memory associated with @a the_key. |
---|
70 | * |
---|
71 | * @param[in] the_key is a pointer to the POSIX key to free |
---|
72 | * the table memory of. |
---|
73 | */ |
---|
74 | void _POSIX_Keys_Free_memory( |
---|
75 | POSIX_Keys_Control *the_key |
---|
76 | ); |
---|
77 | |
---|
78 | /** |
---|
79 | * @brief Free a POSIX keys control block. |
---|
80 | * |
---|
81 | * This routine frees a keys control block to the |
---|
82 | * inactive chain of free keys control blocks. |
---|
83 | * |
---|
84 | * @param[in] the_key is a pointer to the POSIX key to free. |
---|
85 | */ |
---|
86 | RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free ( |
---|
87 | POSIX_Keys_Control *the_key |
---|
88 | ); |
---|
89 | |
---|
90 | /** |
---|
91 | * @brief Allocate a keys control block. |
---|
92 | * |
---|
93 | * This function allocates a keys control block from |
---|
94 | * the inactive chain of free keys control blocks. |
---|
95 | */ |
---|
96 | |
---|
97 | RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Allocate( void ) |
---|
98 | { |
---|
99 | return (POSIX_Keys_Control *) _Objects_Allocate( &_POSIX_Keys_Information ); |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | * @brief Free a keys control block. |
---|
104 | * |
---|
105 | * This routine frees a keys control block to the |
---|
106 | * inactive chain of free keys control blocks. |
---|
107 | */ |
---|
108 | RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free ( |
---|
109 | POSIX_Keys_Control *the_key |
---|
110 | ) |
---|
111 | { |
---|
112 | _Objects_Free( &_POSIX_Keys_Information, &the_key->Object ); |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * @brief Get a keys control block. |
---|
117 | * |
---|
118 | * This function maps key IDs to key control blocks. |
---|
119 | * If ID corresponds to a local keys, then it returns |
---|
120 | * the_key control pointer which maps to ID and location |
---|
121 | * is set to OBJECTS_LOCAL. if the keys ID is global and |
---|
122 | * resides on a remote node, then location is set to OBJECTS_REMOTE, |
---|
123 | * and the_key is undefined. Otherwise, location is set |
---|
124 | * to OBJECTS_ERROR and the_key is undefined. |
---|
125 | */ |
---|
126 | |
---|
127 | RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Get ( |
---|
128 | pthread_key_t id, |
---|
129 | Objects_Locations *location |
---|
130 | ) |
---|
131 | { |
---|
132 | return (POSIX_Keys_Control *) |
---|
133 | _Objects_Get( &_POSIX_Keys_Information, (Objects_Id) id, location ); |
---|
134 | } |
---|
135 | |
---|
136 | POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_pair_allocate( void ); |
---|
137 | |
---|
138 | RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_pair_free( |
---|
139 | POSIX_Keys_Key_value_pair *key_value_pair |
---|
140 | ) |
---|
141 | { |
---|
142 | _Freechain_Put( &_POSIX_Keys_Keypool, key_value_pair ); |
---|
143 | } |
---|
144 | |
---|
145 | RTEMS_INLINE_ROUTINE RBTree_Node *_POSIX_Keys_Find( |
---|
146 | pthread_key_t key, |
---|
147 | Thread_Control *thread |
---|
148 | ) |
---|
149 | { |
---|
150 | POSIX_Keys_Key_value_pair search_node; |
---|
151 | |
---|
152 | search_node.key = key; |
---|
153 | search_node.thread = thread; |
---|
154 | |
---|
155 | return _RBTree_Find( |
---|
156 | &_POSIX_Keys_Key_value_lookup_tree, |
---|
157 | &search_node.Key_value_lookup_node, |
---|
158 | _POSIX_Keys_Key_value_compare, |
---|
159 | true |
---|
160 | ); |
---|
161 | } |
---|
162 | |
---|
163 | RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free_key_value_pair( |
---|
164 | POSIX_Keys_Key_value_pair *key_value_pair |
---|
165 | ) |
---|
166 | { |
---|
167 | _RBTree_Extract( |
---|
168 | &_POSIX_Keys_Key_value_lookup_tree, |
---|
169 | &key_value_pair->Key_value_lookup_node |
---|
170 | ); |
---|
171 | _Chain_Extract_unprotected( &key_value_pair->Key_values_per_thread_node ); |
---|
172 | _POSIX_Keys_Key_value_pair_free( key_value_pair ); |
---|
173 | } |
---|
174 | |
---|
175 | /** @} */ |
---|
176 | |
---|
177 | #ifdef __cplusplus |
---|
178 | } |
---|
179 | #endif |
---|
180 | |
---|
181 | #endif |
---|
182 | /* end of include file */ |
---|