RTEMS  5.0.0
keyimpl.h
Go to the documentation of this file.
1 
10 /*
11  * COPYRIGHT (c) 1989-1999.
12  * On-Line Applications Research Corporation (OAR).
13  * Copyright (c) 2016 embedded brains GmbH.
14  *
15  * The license and distribution terms for this file may be
16  * found in the file LICENSE in this distribution or at
17  * http://www.rtems.org/license/LICENSE.
18  */
19 
20 #include <rtems/posix/key.h>
21 #include <rtems/score/chainimpl.h>
22 #include <rtems/score/freechain.h>
23 #include <rtems/score/objectimpl.h>
24 #include <rtems/score/percpu.h>
25 
26 #ifndef _RTEMS_POSIX_KEYIMPL_H
27 #define _RTEMS_POSIX_KEYIMPL_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
43 
44 #define POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ) \
45  RTEMS_CONTAINER_OF( node, POSIX_Keys_Key_value_pair, Lookup_node )
46 
55 {
57 }
58 
66  POSIX_Keys_Control *the_key
67 )
68 {
70 }
71 
72 RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Get( pthread_key_t key )
73 {
74  return (POSIX_Keys_Control *)
76 }
77 
78 RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_acquire(
79  Thread_Control *the_thread,
80  ISR_lock_Context *lock_context
81 )
82 {
83  _ISR_lock_ISR_disable_and_acquire( &the_thread->Keys.Lock, lock_context );
84 }
85 
86 RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_release(
87  Thread_Control *the_thread,
88  ISR_lock_Context *lock_context
89 )
90 {
91  _ISR_lock_Release_and_ISR_enable( &the_thread->Keys.Lock, lock_context );
92 }
93 
94 POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_allocate( void );
95 
96 RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_free(
97  POSIX_Keys_Key_value_pair *key_value_pair
98 )
99 {
100  _Chain_Extract_unprotected( &key_value_pair->Key_node );
101  _Freechain_Put( &_POSIX_Keys_Keypool, key_value_pair );
102 }
103 
104 RTEMS_INLINE_ROUTINE bool _POSIX_Keys_Key_value_equal(
105  const void *left,
106  const RBTree_Node *right
107 )
108 {
109  const pthread_key_t *the_left;
110  const POSIX_Keys_Key_value_pair *the_right;
111 
112  the_left = left;
113  the_right = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( right );
114 
115  return *the_left == the_right->key;
116 }
117 
118 RTEMS_INLINE_ROUTINE bool _POSIX_Keys_Key_value_less(
119  const void *left,
120  const RBTree_Node *right
121 )
122 {
123  const pthread_key_t *the_left;
124  const POSIX_Keys_Key_value_pair *the_right;
125 
126  the_left = left;
127  the_right = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( right );
128 
129  return *the_left < the_right->key;
130 }
131 
132 RTEMS_INLINE_ROUTINE void *_POSIX_Keys_Key_value_map( RBTree_Node *node )
133 {
134  return POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node );
135 }
136 
137 RTEMS_INLINE_ROUTINE POSIX_Keys_Key_value_pair *_POSIX_Keys_Key_value_find(
138  pthread_key_t key,
139  const Thread_Control *the_thread
140 )
141 {
142  return _RBTree_Find_inline(
143  &the_thread->Keys.Key_value_pairs,
144  &key,
145  _POSIX_Keys_Key_value_equal,
146  _POSIX_Keys_Key_value_less,
147  _POSIX_Keys_Key_value_map
148  );
149 }
150 
151 RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_insert(
152  pthread_key_t key,
153  POSIX_Keys_Key_value_pair *key_value_pair,
154  Thread_Control *the_thread
155 )
156 {
158  &the_thread->Keys.Key_value_pairs,
159  &key_value_pair->Lookup_node,
160  &key,
161  _POSIX_Keys_Key_value_less
162  );
163 }
164 
167 #ifdef __cplusplus
168 }
169 #endif
170 
171 #endif
172 /* end of include file */
RTEMS_INLINE_ROUTINE bool _RBTree_Insert_inline(RBTree_Control *the_rbtree, RBTree_Node *the_node, const void *key, bool(*less)(const void *, const RBTree_Node *))
Inserts the node into the red-black tree.
Definition: rbtree.h:483
void _Objects_Free(Objects_Information *information, Objects_Control *the_object)
Frees an object.
Definition: objectfree.c:25
Freechain_Control _POSIX_Keys_Keypool
This freechain is used as a memory pool for POSIX_Keys_Key_value_pair.
Definition: keycreate.c:54
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:223
Objects_Control * _Objects_Allocate(Objects_Information *information)
Allocates an object.
Definition: objectallocate.c:89
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
Represents POSIX key and value pair.
Definition: key.h:46
Thread_Keys_information Keys
The POSIX Keys information.
Definition: thread.h:848
RTEMS_INLINE_ROUTINE void _Chain_Extract_unprotected(Chain_Node *the_node)
Extract this node (unprotected).
Definition: chainimpl.h:557
Red-black tree node.
Definition: rbtree.h:50
Chain_Node Key_node
The chain node for the key value pairs chain in POSIX_Keys_Control.
Definition: key.h:50
Objects_Control * _Objects_Get_no_protection(Objects_Id id, const Objects_Information *information)
Maps object ids to object control blocks.
Definition: objectgetnoprotection.c:23
RTEMS_INLINE_ROUTINE void * _RBTree_Find_inline(const RBTree_Control *the_rbtree, const void *key, bool(*equal)(const void *, const RBTree_Node *), bool(*less)(const void *, const RBTree_Node *), void *(*map)(RBTree_Node *))
Finds an object in the red-black tree with the specified key.
Definition: rbtree.h:532
Definition: thread.h:728
void _Freechain_Put(Freechain_Control *freechain, void *node)
Puts a node back onto the freechain.
Definition: freechain.c:50
Objects_Information _POSIX_Keys_Information
The POSIX Key objects information.
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:248
RBTree_Control Key_value_pairs
Key value pairs registered for this thread.
Definition: thread.h:648
RTEMS_INLINE_ROUTINE POSIX_Keys_Control * _POSIX_Keys_Allocate(void)
Allocate a keys control block.
Definition: keyimpl.h:54
Chain Handler API.
RBTree_Node Lookup_node
The tree node for the lookup tree in Thread_Keys_information.
Definition: key.h:55
RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free(POSIX_Keys_Control *the_key)
Free a keys control block.
Definition: keyimpl.h:65
Freechain Handler API.
The data structure used to manage a POSIX key.
Definition: key.h:94
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Inlined Routines in the Object Handler.
POSIX Key Private Support.
uint32_t Objects_Id
Definition: object.h:75
pthread_key_t key
The POSIX key identifier used as the tree key.
Definition: key.h:60
Objects_Control Object
Definition: key.h:96
The freechain control.
Definition: freechain.h:46