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

5
Last change on this file since 21275b58 was 21275b58, checked in by Sebastian Huber <sebastian.huber@…>, on 11/22/18 at 18:14:51

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
RevLine 
[2ad250e]1/**
2 * @file
[f65e8e6]3 *
[2ad250e]4 * @brief Private Inlined Routines for POSIX Key's
5 *
[f65e8e6]6 * This include file contains the static inline implementation of the private
[2ad250e]7 * inlined routines for POSIX key's.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-1999.
12 *  On-Line Applications Research Corporation (OAR).
[5eaf0e7]13 *  Copyright (c) 2016 embedded brains GmbH.
[2ad250e]14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
[c499856]17 *  http://www.rtems.org/license/LICENSE.
[2ad250e]18 */
[f65e8e6]19
[2ad250e]20#include <rtems/posix/key.h>
[172e953]21#include <rtems/score/chainimpl.h>
[2ad250e]22#include <rtems/score/freechain.h>
23#include <rtems/score/objectimpl.h>
[f65e8e6]24#include <rtems/score/percpu.h>
[2ad250e]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 */
[2605a489]42extern Freechain_Control _POSIX_Keys_Keypool;
[2ad250e]43
[40dcafa]44#define POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ) \
[5eaf0e7]45  RTEMS_CONTAINER_OF( node, POSIX_Keys_Key_value_pair, Lookup_node )
[f65e8e6]46
[2ad250e]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 */
[f65e8e6]53
[2ad250e]54RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Allocate( void )
55{
56  return (POSIX_Keys_Control *) _Objects_Allocate( &_POSIX_Keys_Information );
57}
[f65e8e6]58
[2ad250e]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 */
[5eaf0e7]65RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free(
[2ad250e]66  POSIX_Keys_Control *the_key
67)
68{
69  _Objects_Free( &_POSIX_Keys_Information, &the_key->Object );
70}
[f65e8e6]71
[5eaf0e7]72RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Get( pthread_key_t key )
73{
[572cb624]74  return (POSIX_Keys_Control *)
[d7a12be9]75    _Objects_Get_no_protection( (Objects_Id) key, &_POSIX_Keys_Information );
[5eaf0e7]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}
[f65e8e6]85
[5eaf0e7]86RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_release(
87  Thread_Control   *the_thread,
88  ISR_lock_Context *lock_context
[2ad250e]89)
90{
[5eaf0e7]91  _ISR_lock_Release_and_ISR_enable( &the_thread->Keys.Lock, lock_context );
[2ad250e]92}
93
[5eaf0e7]94POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_allocate( void );
[c9b784f]95
[5eaf0e7]96RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_free(
[c9b784f]97  POSIX_Keys_Key_value_pair *key_value_pair
98)
99{
[5eaf0e7]100  _Chain_Extract_unprotected( &key_value_pair->Key_node );
[c9b784f]101  _Freechain_Put( &_POSIX_Keys_Keypool, key_value_pair );
102}
103
[97127aa]104RTEMS_INLINE_ROUTINE bool _POSIX_Keys_Key_value_equal(
105  const void        *left,
106  const RBTree_Node *right
[64939bc]107)
108{
[97127aa]109  const pthread_key_t             *the_left;
110  const POSIX_Keys_Key_value_pair *the_right;
[5eaf0e7]111
[97127aa]112  the_left = left;
113  the_right = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( right );
[5eaf0e7]114
[97127aa]115  return *the_left == the_right->key;
116}
[5eaf0e7]117
[97127aa]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;
[5eaf0e7]125
[97127aa]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}
[5eaf0e7]131
[9ea69dee]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(
[0cc6071]138  pthread_key_t         key,
139  const Thread_Control *the_thread
[97127aa]140)
141{
142  return _RBTree_Find_inline(
143    &the_thread->Keys.Key_value_pairs,
144    &key,
145    _POSIX_Keys_Key_value_equal,
[9ea69dee]146    _POSIX_Keys_Key_value_less,
147    _POSIX_Keys_Key_value_map
[97127aa]148  );
[64939bc]149}
150
[5eaf0e7]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
[172e953]155)
156{
[9eaf564]157  _RBTree_Insert_inline(
[5eaf0e7]158    &the_thread->Keys.Key_value_pairs,
[9eaf564]159    &key_value_pair->Lookup_node,
160    &key,
161    _POSIX_Keys_Key_value_less
[172e953]162  );
163}
164
[2ad250e]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.