RTEMS 6.1-rc6
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}
104
105static inline void _POSIX_Keys_Key_value_release(
106 Thread_Control *the_thread,
107 ISR_lock_Context *lock_context
108)
109{
110 _ISR_lock_Release_and_ISR_enable( &the_thread->Keys.Lock, lock_context );
111}
112
113POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_allocate( void );
114
115static inline void _POSIX_Keys_Key_value_free(
116 POSIX_Keys_Key_value_pair *key_value_pair
117)
118{
119 _Chain_Extract_unprotected( &key_value_pair->Key_node );
120 _Freechain_Put( &_POSIX_Keys_Keypool, key_value_pair );
121}
122
123static inline bool _POSIX_Keys_Key_value_equal(
124 const void *left,
125 const RBTree_Node *right
126)
127{
128 const pthread_key_t *the_left;
129 const POSIX_Keys_Key_value_pair *the_right;
130
131 the_left = left;
132 the_right = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( right );
133
134 return *the_left == the_right->key;
135}
136
137static inline bool _POSIX_Keys_Key_value_less(
138 const void *left,
139 const RBTree_Node *right
140)
141{
142 const pthread_key_t *the_left;
143 const POSIX_Keys_Key_value_pair *the_right;
144
145 the_left = left;
146 the_right = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( right );
147
148 return *the_left < the_right->key;
149}
150
151static inline void *_POSIX_Keys_Key_value_map( RBTree_Node *node )
152{
153 return POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node );
154}
155
156static inline POSIX_Keys_Key_value_pair *_POSIX_Keys_Key_value_find(
157 pthread_key_t key,
158 const Thread_Control *the_thread
159)
160{
161 return _RBTree_Find_inline(
162 &the_thread->Keys.Key_value_pairs,
163 &key,
164 _POSIX_Keys_Key_value_equal,
165 _POSIX_Keys_Key_value_less,
166 _POSIX_Keys_Key_value_map
167 );
168}
169
170static inline void _POSIX_Keys_Key_value_insert(
171 pthread_key_t key,
172 POSIX_Keys_Key_value_pair *key_value_pair,
173 Thread_Control *the_thread
174)
175{
176 _RBTree_Insert_inline(
177 &the_thread->Keys.Key_value_pairs,
178 &key_value_pair->Lookup_node,
179 &key,
180 _POSIX_Keys_Key_value_less
181 );
182}
183
186#ifdef __cplusplus
187}
188#endif
189
190#endif
191/* 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