source: rtems/cpukit/posix/include/rtems/posix/keyimpl.h @ fdb45d6

4.115
Last change on this file since fdb45d6 was fdb45d6, checked in by Sebastian Huber <sebastian.huber@…>, on 06/24/15 at 12:00:08

score: Freechain handler API changes

Replace the extend function with an allocator since this fits better
to the current use case.

  • Property mode set to 100644
File size: 5.0 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/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
29extern "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 */
41POSIX_EXTERN Objects_Information  _POSIX_Keys_Information;
42
43/**
44 * @brief The rbtree control block used to manage all key values
45 */
46extern 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 */
51POSIX_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 key manager initialization.
58 *
59 * This routine performs the initialization necessary for this manager.
60 */
61void _POSIX_Key_Manager_initialization(void);
62
63/**
64 * @brief POSIX keys Red-Black tree node comparison.
65 *
66 * This routine compares the rbtree node
67 */
68RBTree_Compare_result _POSIX_Keys_Key_value_compare(
69  const RBTree_Node *node1,
70  const RBTree_Node *node2
71);
72
73/**
74 * @brief Create thread-specific data POSIX key.
75 *
76 * This function executes all the destructors associated with the thread's
77 * keys.  This function will execute until all values have been set to NULL.
78 *
79 * @param[in] thread is a pointer to the thread whose keys should have
80 *            all their destructors run.
81 *
82 * NOTE: This is the routine executed when a thread exits to
83 *       run through all the keys and do the destructor action.
84 */
85void _POSIX_Keys_Run_destructors(
86  Thread_Control *thread
87);
88
89/**
90 * @brief Free a POSIX key table memory.
91 *
92 * This memory frees the key table memory associated with @a the_key.
93 *
94 * @param[in] the_key is a pointer to the POSIX key to free
95 * the table memory of.
96 */
97void _POSIX_Keys_Free_memory(
98  POSIX_Keys_Control *the_key
99);
100
101/**
102 * @brief Free a POSIX keys control block.
103 *
104 * This routine frees a keys control block to the
105 * inactive chain of free keys control blocks.
106 *
107 * @param[in] the_key is a pointer to the POSIX key to free.
108 */
109RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free (
110  POSIX_Keys_Control *the_key
111);
112
113/**
114 * @brief Allocate a keys control block.
115 *
116 * This function allocates a keys control block from
117 * the inactive chain of free keys control blocks.
118 */
119
120RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Allocate( void )
121{
122  return (POSIX_Keys_Control *) _Objects_Allocate( &_POSIX_Keys_Information );
123}
124
125/**
126 * @brief Free a keys control block.
127 *
128 * This routine frees a keys control block to the
129 * inactive chain of free keys control blocks.
130 */
131RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free (
132  POSIX_Keys_Control *the_key
133)
134{
135  _Objects_Free( &_POSIX_Keys_Information, &the_key->Object );
136}
137
138/**
139 * @brief Get a keys control block.
140 *
141 * This function maps key IDs to key control blocks.
142 * If ID corresponds to a local keys, then it returns
143 * the_key control pointer which maps to ID and location
144 * is set to OBJECTS_LOCAL.  if the keys ID is global and
145 * resides on a remote node, then location is set to OBJECTS_REMOTE,
146 * and the_key is undefined.  Otherwise, location is set
147 * to OBJECTS_ERROR and the_key is undefined.
148 */
149
150RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Get (
151  pthread_key_t      id,
152  Objects_Locations *location
153)
154{
155  return (POSIX_Keys_Control *)
156    _Objects_Get( &_POSIX_Keys_Information, (Objects_Id) id, location );
157}
158
159POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_pair_allocate( void );
160
161RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_pair_free(
162  POSIX_Keys_Key_value_pair *key_value_pair
163)
164{
165  _Freechain_Put( &_POSIX_Keys_Keypool, key_value_pair );
166}
167
168RTEMS_INLINE_ROUTINE RBTree_Node *_POSIX_Keys_Find(
169  pthread_key_t   key,
170  Thread_Control *thread
171)
172{
173  POSIX_Keys_Key_value_pair search_node;
174
175  search_node.key = key;
176  search_node.thread = thread;
177
178  return _RBTree_Find(
179    &_POSIX_Keys_Key_value_lookup_tree,
180    &search_node.Key_value_lookup_node,
181    _POSIX_Keys_Key_value_compare,
182    true
183  );
184}
185
186RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free_key_value_pair(
187  POSIX_Keys_Key_value_pair *key_value_pair
188)
189{
190  _RBTree_Extract(
191    &_POSIX_Keys_Key_value_lookup_tree,
192    &key_value_pair->Key_value_lookup_node
193  );
194  _Chain_Extract_unprotected( &key_value_pair->Key_values_per_thread_node );
195  _POSIX_Keys_Key_value_pair_free( key_value_pair );
196}
197
198/** @} */
199
200#ifdef __cplusplus
201}
202#endif
203
204#endif
205/*  end of include file */
Note: See TracBrowser for help on using the repository browser.