source: rtems/cpukit/posix/include/rtems/posix/key.h @ b5c9064

4.115
Last change on this file since b5c9064 was b5c9064, checked in by Zhongwei Yao <ashi08104@…>, on Aug 5, 2013 at 1:20:45 PM

Unlimited objects support for POSIX keys

This patch enables unlimited model in POSIX key manger and have a decent
runtime on POSIX key searching, adding and deleting operations. Memory
overhead is lower than current implementation when the size of key and key
value becomes big.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Key Private Support
5 *
6 * This include file contains all the private support information for
7 * POSIX key.
8 */
9
10/*
11 * Copyright (c) 2012 Zhongwei Yao.
12 * COPYRIGHT (c) 1989-2011.
13 * On-Line Applications Research Corporation (OAR).
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.com/license/LICENSE.
18 */
19
20#ifndef _RTEMS_POSIX_KEY_H
21#define _RTEMS_POSIX_KEY_H
22
23#include <rtems/score/rbtree.h>
24#include <rtems/score/chainimpl.h>
25#include <rtems/score/freechain.h>
26#include <rtems/score/objectimpl.h>
27
28/**
29 * @defgroup POSIX_KEY POSIX Key
30 *
31 * @ingroup POSIXAPI
32 *
33 */
34/**@{**/
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/**
41 * @brief The rbtree node used to manage a POSIX key and value.
42 */
43typedef struct {
44  /** This field is the chain node structure. */
45  Chain_Node Key_values_per_thread_node;
46  /** This field is the rbtree node structure. */
47  RBTree_Node Key_value_lookup_node;
48  /** This field is the POSIX key used as an rbtree key */
49  pthread_key_t key;
50  /** This field is the Thread id also used as an rbtree key */
51  Objects_Id thread_id;
52  /** This field points to the POSIX key value of specific thread */
53  void *value;
54}  POSIX_Keys_Key_value_pair;
55
56/**
57 * @brief POSIX_Keys_Freechain is used in Freechain structure
58 */
59typedef struct {
60    Freechain_Control super_fc;
61    size_t bump_count;
62} POSIX_Keys_Freechain;
63
64/**
65 * @brief The data structure used to manage a POSIX key.
66 */
67typedef struct {
68   /** This field is the Object control structure. */
69   Objects_Control     Object;
70   /** This field is the data destructor. */
71   void (*destructor) (void *);
72 }  POSIX_Keys_Control;
73
74/**
75 * @brief The information control block used to manage this class of objects.
76 */
77POSIX_EXTERN Objects_Information  _POSIX_Keys_Information;
78
79/**
80 * @brief The rbtree control block used to manage all key values
81 */
82POSIX_EXTERN RBTree_Control _POSIX_Keys_Key_value_lookup_tree;
83
84/**
85 * @brief This freechain is used as a memory pool for POSIX_Keys_Key_value_pair.
86 */
87POSIX_EXTERN POSIX_Keys_Freechain _POSIX_Keys_Keypool;
88
89/**
90 * @brief POSIX key manager initialization.
91 *
92 * This routine performs the initialization necessary for this manager.
93 */
94void _POSIX_Key_Manager_initialization(void);
95
96/**
97 * @brief POSIX key Freechain extend handle
98 *
99 * This routine extend freechain node, which is called in freechain_get
100 * automatically.
101 */
102bool _POSIX_Keys_Freechain_extend(Freechain_Control *freechain);
103
104/**
105 * @brief POSIX keys Red-Black tree node comparison.
106 *
107 * This routine compares the rbtree node
108 */
109int _POSIX_Keys_Key_value_lookup_tree_compare_function(
110  const RBTree_Node *node1,
111  const RBTree_Node *node2
112);
113
114/**
115 * @brief Create thread-specific data POSIX key.
116 *
117 * This function executes all the destructors associated with the thread's
118 * keys.  This function will execute until all values have been set to NULL.
119 *
120 * @param[in] thread is a pointer to the thread whose keys should have
121 *            all their destructors run.
122 *
123 * NOTE: This is the routine executed when a thread exits to
124 *       run through all the keys and do the destructor action.
125 */
126void _POSIX_Keys_Run_destructors(
127  Thread_Control *thread
128);
129
130/**
131 * @brief Free a POSIX key table memory.
132 *
133 * This memory frees the key table memory associated with @a the_key.
134 *
135 * @param[in] the_key is a pointer to the POSIX key to free
136 * the table memory of.
137 */
138void _POSIX_Keys_Free_memory(
139  POSIX_Keys_Control *the_key
140);
141
142/**
143 * @brief Free a POSIX keys control block.
144 *
145 * This routine frees a keys control block to the
146 * inactive chain of free keys control blocks.
147 *
148 * @param[in] the_key is a pointer to the POSIX key to free.
149 */
150RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free (
151  POSIX_Keys_Control *the_key
152);
153
154#include <rtems/posix/key.inl>
155
156/** @} */
157
158#ifdef __cplusplus
159}
160#endif
161
162#endif
163/*  end of include file */
Note: See TracBrowser for help on using the repository browser.