source: rtems/cpukit/include/rtems/posix/keyimpl.h @ 21275b58

Last change on this file since 21275b58 was 21275b58, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 22, 2018 at 6:14:51 PM

score: Static Objects_Information initialization

Statically allocate the objects information together with the initial
set of objects either via <rtems/confdefs.h>. Provide default object
informations with zero objects via librtemscpu.a. This greatly
simplifies the workspace size estimate. RTEMS applications which do not
use the unlimited objects option are easier to debug since all objects
reside now in statically allocated objects of the right types.

Close #3621.

  • Property mode set to 100644
File size: 4.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 *  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
33/**
34 * @addtogroup POSIX_KEY
35 *
36 * @{
37 */
38
39/**
40 * @brief This freechain is used as a memory pool for POSIX_Keys_Key_value_pair.
41 */
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
47/**
48 * @brief Allocate a keys control block.
49 *
50 * This function allocates a keys control block from
51 * the inactive chain of free keys control blocks.
52 */
53
54RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Allocate( void )
55{
56  return (POSIX_Keys_Control *) _Objects_Allocate( &_POSIX_Keys_Information );
57}
58
59/**
60 * @brief Free a keys control block.
61 *
62 * This routine frees a keys control block to the
63 * inactive chain of free keys control blocks.
64 */
65RTEMS_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
72RTEMS_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
78RTEMS_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
86RTEMS_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
94POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_allocate( void );
95
96RTEMS_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
104RTEMS_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
118RTEMS_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
132RTEMS_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
137RTEMS_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
151RTEMS_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
165/** @} */
166
167#ifdef __cplusplus
168}
169#endif
170
171#endif
172/*  end of include file */
Note: See TracBrowser for help on using the repository browser.