Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:12

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief Private Inlined Routines for POSIX Key's
0007  *
0008  * This include file contains the static inline implementation of the private
0009  * inlined routines for POSIX key's.
0010  */
0011 
0012 /*
0013  *  COPYRIGHT (c) 1989-1999.
0014  *  On-Line Applications Research Corporation (OAR).
0015  *  Copyright (c) 2016 embedded brains GmbH & Co. KG
0016  *
0017  * Redistribution and use in source and binary forms, with or without
0018  * modification, are permitted provided that the following conditions
0019  * are met:
0020  * 1. Redistributions of source code must retain the above copyright
0021  *    notice, this list of conditions and the following disclaimer.
0022  * 2. Redistributions in binary form must reproduce the above copyright
0023  *    notice, this list of conditions and the following disclaimer in the
0024  *    documentation and/or other materials provided with the distribution.
0025  *
0026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0036  * POSSIBILITY OF SUCH DAMAGE.
0037  */
0038 
0039 #include <rtems/posix/key.h>
0040 #include <rtems/score/chainimpl.h>
0041 #include <rtems/score/freechainimpl.h>
0042 #include <rtems/score/objectimpl.h>
0043 #include <rtems/score/percpu.h>
0044 
0045 #ifndef _RTEMS_POSIX_KEYIMPL_H
0046 #define _RTEMS_POSIX_KEYIMPL_H
0047 
0048 #ifdef __cplusplus
0049 extern "C" {
0050 #endif
0051 
0052 /**
0053  * @addtogroup POSIX_KEY
0054  *
0055  * @{
0056  */
0057 
0058 /**
0059  * @brief This freechain is used as a memory pool for POSIX_Keys_Key_value_pair.
0060  */
0061 extern Freechain_Control _POSIX_Keys_Keypool;
0062 
0063 #define POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ) \
0064   RTEMS_CONTAINER_OF( node, POSIX_Keys_Key_value_pair, Lookup_node )
0065 
0066 /**
0067  * @brief Allocate a keys control block.
0068  *
0069  * This function allocates a keys control block from
0070  * the inactive chain of free keys control blocks.
0071  */
0072 
0073 static inline POSIX_Keys_Control *_POSIX_Keys_Allocate( void )
0074 {
0075   return (POSIX_Keys_Control *) _Objects_Allocate( &_POSIX_Keys_Information );
0076 }
0077 
0078 /**
0079  * @brief Free a keys control block.
0080  *
0081  * This routine frees a keys control block to the
0082  * inactive chain of free keys control blocks.
0083  */
0084 static inline void _POSIX_Keys_Free(
0085   POSIX_Keys_Control *the_key
0086 )
0087 {
0088   _Objects_Free( &_POSIX_Keys_Information, &the_key->Object );
0089 }
0090 
0091 static inline POSIX_Keys_Control *_POSIX_Keys_Get( pthread_key_t key )
0092 {
0093   return (POSIX_Keys_Control *)
0094     _Objects_Get_no_protection( (Objects_Id) key, &_POSIX_Keys_Information );
0095 }
0096 
0097 static inline void _POSIX_Keys_Key_value_acquire(
0098   Thread_Control   *the_thread,
0099   ISR_lock_Context *lock_context
0100 )
0101 {
0102   _ISR_lock_ISR_disable_and_acquire( &the_thread->Keys.Lock, lock_context );
0103 }
0104 
0105 static inline void _POSIX_Keys_Key_value_release(
0106   Thread_Control   *the_thread,
0107   ISR_lock_Context *lock_context
0108 )
0109 {
0110   _ISR_lock_Release_and_ISR_enable( &the_thread->Keys.Lock, lock_context );
0111 }
0112 
0113 POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_allocate( void );
0114 
0115 static inline void _POSIX_Keys_Key_value_free(
0116   POSIX_Keys_Key_value_pair *key_value_pair
0117 )
0118 {
0119   _Chain_Extract_unprotected( &key_value_pair->Key_node );
0120   _Freechain_Put( &_POSIX_Keys_Keypool, key_value_pair );
0121 }
0122 
0123 static inline bool _POSIX_Keys_Key_value_equal(
0124   const void        *left,
0125   const RBTree_Node *right
0126 )
0127 {
0128   const pthread_key_t             *the_left;
0129   const POSIX_Keys_Key_value_pair *the_right;
0130 
0131   the_left = left;
0132   the_right = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( right );
0133 
0134   return *the_left == the_right->key;
0135 }
0136 
0137 static inline bool _POSIX_Keys_Key_value_less(
0138   const void        *left,
0139   const RBTree_Node *right
0140 )
0141 {
0142   const pthread_key_t             *the_left;
0143   const POSIX_Keys_Key_value_pair *the_right;
0144 
0145   the_left = left;
0146   the_right = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( right );
0147 
0148   return *the_left < the_right->key;
0149 }
0150 
0151 static inline void *_POSIX_Keys_Key_value_map( RBTree_Node *node )
0152 {
0153   return POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node );
0154 }
0155 
0156 static inline POSIX_Keys_Key_value_pair *_POSIX_Keys_Key_value_find(
0157   pthread_key_t         key,
0158   const Thread_Control *the_thread
0159 )
0160 {
0161   return _RBTree_Find_inline(
0162     &the_thread->Keys.Key_value_pairs,
0163     &key,
0164     _POSIX_Keys_Key_value_equal,
0165     _POSIX_Keys_Key_value_less,
0166     _POSIX_Keys_Key_value_map
0167   );
0168 }
0169 
0170 static inline void _POSIX_Keys_Key_value_insert(
0171   pthread_key_t              key,
0172   POSIX_Keys_Key_value_pair *key_value_pair,
0173   Thread_Control            *the_thread
0174 )
0175 {
0176   _RBTree_Insert_inline(
0177     &the_thread->Keys.Key_value_pairs,
0178     &key_value_pair->Lookup_node,
0179     &key,
0180     _POSIX_Keys_Key_value_less
0181   );
0182 }
0183 
0184 /** @} */
0185 
0186 #ifdef __cplusplus
0187 }
0188 #endif
0189 
0190 #endif
0191 /*  end of include file */