RTEMS 7.0-rc1
Loading...
Searching...
No Matches
keyimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * COPYRIGHT (c) 1989-1999.
14 * On-Line Applications Research Corporation (OAR).
15 * Copyright (c) 2016 embedded brains GmbH & Co. KG
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#include <rtems/posix/key.h>
43#include <rtems/score/percpu.h>
44
45#ifndef _RTEMS_POSIX_KEYIMPL_H
46#define _RTEMS_POSIX_KEYIMPL_H
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
62
63#define POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ) \
64 RTEMS_CONTAINER_OF( node, POSIX_Keys_Key_value_pair, Lookup_node )
65
73static inline POSIX_Keys_Control *_POSIX_Keys_Allocate( void )
74{
76}
77
84static inline void _POSIX_Keys_Free(
85 POSIX_Keys_Control *the_key
86)
87{
88 _Objects_Free( &_POSIX_Keys_Information, &the_key->Object );
89}
90
91static inline POSIX_Keys_Control *_POSIX_Keys_Get( pthread_key_t key )
92{
93 return (POSIX_Keys_Control *)
95}
96
97static inline void _POSIX_Keys_Key_value_acquire(
98 Thread_Control *the_thread,
99 ISR_lock_Context *lock_context
100)
101{
102 _ISR_lock_ISR_disable_and_acquire( &the_thread->Keys.Lock, lock_context );
103#ifndef RTEMS_SMP
104 (void) the_thread;
105#endif
106}
107
108static inline void _POSIX_Keys_Key_value_release(
109 Thread_Control *the_thread,
110 ISR_lock_Context *lock_context
111)
112{
113 _ISR_lock_Release_and_ISR_enable( &the_thread->Keys.Lock, lock_context );
114#ifndef RTEMS_SMP
115 (void) the_thread;
116#endif
117}
118
119POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_allocate( void );
120
121static inline void _POSIX_Keys_Key_value_free(
122 POSIX_Keys_Key_value_pair *key_value_pair
123)
124{
125 _Chain_Extract_unprotected( &key_value_pair->Key_node );
126 _Freechain_Put( &_POSIX_Keys_Keypool, key_value_pair );
127}
128
129static inline bool _POSIX_Keys_Key_value_equal(
130 const void *left,
131 const RBTree_Node *right
132)
133{
134 const pthread_key_t *the_left;
135 const POSIX_Keys_Key_value_pair *the_right;
136
137 the_left = left;
138 the_right = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( right );
139
140 return *the_left == the_right->key;
141}
142
143static inline bool _POSIX_Keys_Key_value_less(
144 const void *left,
145 const RBTree_Node *right
146)
147{
148 const pthread_key_t *the_left;
149 const POSIX_Keys_Key_value_pair *the_right;
150
151 the_left = left;
152 the_right = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( right );
153
154 return *the_left < the_right->key;
155}
156
157static inline void *_POSIX_Keys_Key_value_map( RBTree_Node *node )
158{
159 return POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node );
160}
161
162static inline POSIX_Keys_Key_value_pair *_POSIX_Keys_Key_value_find(
163 pthread_key_t key,
164 const Thread_Control *the_thread
165)
166{
167 return _RBTree_Find_inline(
168 &the_thread->Keys.Key_value_pairs,
169 &key,
170 _POSIX_Keys_Key_value_equal,
171 _POSIX_Keys_Key_value_less,
172 _POSIX_Keys_Key_value_map
173 );
174}
175
176static inline void _POSIX_Keys_Key_value_insert(
177 pthread_key_t key,
178 POSIX_Keys_Key_value_pair *key_value_pair,
179 Thread_Control *the_thread
180)
181{
182 _RBTree_Insert_inline(
183 &the_thread->Keys.Key_value_pairs,
184 &key_value_pair->Lookup_node,
185 &key,
186 _POSIX_Keys_Key_value_less
187 );
188}
189
192#ifdef __cplusplus
193}
194#endif
195
196#endif
197/* end of include file */
This header file provides interfaces of the Chain Handler which are only used by the implementation.
This header file provides interfaces of the Barrier Handler which are only used by the implementation...
Freechain_Control _POSIX_Keys_Keypool
This freechain is used as a memory pool for POSIX_Keys_Key_value_pair.
Definition: keycreate.c:74
Objects_Information _POSIX_Keys_Information
The POSIX Key objects information.
void _Freechain_Put(Freechain_Control *freechain, void *node)
Puts a node back onto the freechain.
Definition: freechain.c:87
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:229
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:204
Objects_Control * _Objects_Allocate(Objects_Information *information)
Allocates an object.
Definition: objectallocate.c:43
uint32_t Objects_Id
Definition: object.h:101
Objects_Control * _Objects_Get_no_protection(Objects_Id id, const Objects_Information *information)
Maps object ids to object control blocks.
Definition: objectgetnoprotection.c:44
POSIX Key Private Support.
This header file provides interfaces of the Object Handler which are only used by the implementation.
This header file provides the interfaces of the Per-CPU Information.
The freechain control.
Definition: freechain.h:64
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:94
The data structure used to manage a POSIX key.
Definition: key.h:113
Objects_Control Object
Definition: key.h:115
Represents POSIX key and value pair.
Definition: key.h:65
pthread_key_t key
The POSIX key identifier used as the tree key.
Definition: key.h:79
Chain_Node Key_node
The chain node for the key value pairs chain in POSIX_Keys_Control.
Definition: key.h:69
RBTree_Node Lookup_node
The tree node for the lookup tree in Thread_Keys_information.
Definition: key.h:74
Red-black tree node.
Definition: rbtree.h:73
RBTree_Control Key_value_pairs
Key value pairs registered for this thread.
Definition: thread.h:718
Definition: thread.h:837
Thread_Keys_information Keys
The POSIX Keys information.
Definition: thread.h:978