RTEMS: cpukit/include/rtems/posix/keyimpl.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
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
30extern "C" {
31#endif
32
42extern Freechain_Control _POSIX_Keys_Keypool;
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
54 RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Allocate( void )
55{
56 return (POSIX_Keys_Control *) _Objects_Allocate( &_POSIX_Keys_Information );
57}
58
65 RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free(
66 POSIX_Keys_Control *the_key
67)
68{
69 _Objects_Free( &_POSIX_Keys_Information, &the_key->Object );
70}
71
72 RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Get( pthread_key_t key )
73{
74 return (POSIX_Keys_Control *)
75 _Objects_Get_no_protection( (Objects_Id) key, &_POSIX_Keys_Information );
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{
157 _RBTree_Insert_inline(
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 */
chainimpl.h
Chain Handler API.
freechain.h
Freechain Handler API.
_POSIX_Keys_Keypool
Freechain_Control _POSIX_Keys_Keypool
This freechain is used as a memory pool for POSIX_Keys_Key_value_pair.
Definition: keycreate.c:55
_POSIX_Keys_Allocate
RTEMS_INLINE_ROUTINE POSIX_Keys_Control * _POSIX_Keys_Allocate(void)
Allocate a keys control block.
Definition: keyimpl.h:54
_POSIX_Keys_Free
RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free(POSIX_Keys_Control *the_key)
Free a keys control block.
Definition: keyimpl.h:65
_POSIX_Keys_Information
Objects_Information _POSIX_Keys_Information
The POSIX Key objects information.
RTEMS_INLINE_ROUTINE
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
_Chain_Extract_unprotected
RTEMS_INLINE_ROUTINE void _Chain_Extract_unprotected(Chain_Node *the_node)
Extracts this node (unprotected).
Definition: chainimpl.h:558
_Freechain_Put
void _Freechain_Put(Freechain_Control *freechain, void *node)
Puts a node back onto the freechain.
Definition: freechain.c:67
_ISR_lock_Release_and_ISR_enable
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:263
_ISR_lock_ISR_disable_and_acquire
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:238
_Objects_Free
RTEMS_INLINE_ROUTINE void _Objects_Free(Objects_Information *information, Objects_Control *the_object)
Frees an object.
Definition: objectimpl.h:930
_Objects_Allocate
Objects_Control * _Objects_Allocate(Objects_Information *information)
Allocates an object.
Definition: objectallocate.c:42
Objects_Id
uint32_t Objects_Id
Definition: object.h:80
_Objects_Get_no_protection
Objects_Control * _Objects_Get_no_protection(Objects_Id id, const Objects_Information *information)
Maps object ids to object control blocks.
Definition: objectgetnoprotection.c:23
_RBTree_Find_inline
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:557
_RBTree_Insert_inline
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:508
key.h
POSIX Key Private Support.
objectimpl.h
Inlined Routines in the Object Handler.
percpu.h
Freechain_Control
The freechain control.
Definition: freechain.h:48
ISR_lock_Context
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
POSIX_Keys_Control
The data structure used to manage a POSIX key.
Definition: key.h:94
POSIX_Keys_Control::Object
Objects_Control Object
Definition: key.h:96
POSIX_Keys_Key_value_pair
Represents POSIX key and value pair.
Definition: key.h:46
POSIX_Keys_Key_value_pair::key
pthread_key_t key
The POSIX key identifier used as the tree key.
Definition: key.h:60
POSIX_Keys_Key_value_pair::Key_node
Chain_Node Key_node
The chain node for the key value pairs chain in POSIX_Keys_Control.
Definition: key.h:50
POSIX_Keys_Key_value_pair::Lookup_node
RBTree_Node Lookup_node
The tree node for the lookup tree in Thread_Keys_information.
Definition: key.h:55
RBTree_Node
Red-black tree node.
Definition: rbtree.h:55
Thread_Keys_information::Key_value_pairs
RBTree_Control Key_value_pairs
Key value pairs registered for this thread.
Definition: thread.h:652
_Thread_Control
Definition: thread.h:732
_Thread_Control::Keys
Thread_Keys_information Keys
The POSIX Keys information.
Definition: thread.h:852