1 | /* |
---|
2 | * grdxt.h - Three-levels Generic Radix-tree definition. |
---|
3 | * |
---|
4 | * Authors Alain Greiner (2016,2017,2018,2019) |
---|
5 | * |
---|
6 | * Copyright UPMC Sorbonne Universites |
---|
7 | * |
---|
8 | * This file is part of ALMOS-MKH. |
---|
9 | * |
---|
10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
11 | * under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; version 2.0 of the License. |
---|
13 | * |
---|
14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | * General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef _GRDXT_H_ |
---|
25 | #define _GRDXT_H_ |
---|
26 | |
---|
27 | #include <hal_kernel_types.h> |
---|
28 | |
---|
29 | /******************************************************************************************* |
---|
30 | * This structure defines a three levels radix-tree descriptor. |
---|
31 | * The key is split in three fields : ix1 (MSB) / ix2 / ix3 (LSB) to index the first, |
---|
32 | * second and third level arrays respectively. |
---|
33 | * The pointers on the registered items are stored in the third level arrays. |
---|
34 | * The number or bits for each field are parameters for the grdxt_init() function. |
---|
35 | * Memory for the first level array is allocated by the grdxt_init() function. |
---|
36 | * Memory for the second and third levels arrays is dynamically allocated by the |
---|
37 | * grdxt_insert() function and is only released by grdxt_destroy(). |
---|
38 | * This structure is entirely contained in one single cluster, but to allow any thread |
---|
39 | * to access it, two sets of access functions are defined: |
---|
40 | * - local threads can use access function using local pointers. |
---|
41 | * - remote threads must use the access functions using extended pointers. |
---|
42 | ****************************************************************************************** |
---|
43 | * When it is used by the mapper implementing the file cache: |
---|
44 | * - the key is the page index in file. |
---|
45 | * - the registered value is a local pointer on the page descriptor. |
---|
46 | ******************************************************************************************/ |
---|
47 | |
---|
48 | typedef struct grdxt_s |
---|
49 | { |
---|
50 | void ** root; /*! pointer on first level array of pointers */ |
---|
51 | uint32_t ix1_width; /*! number of bits for first level array index */ |
---|
52 | uint32_t ix2_width; /*! number of bits for second level array index */ |
---|
53 | uint32_t ix3_width; /*! number of bits for third level array index */ |
---|
54 | } |
---|
55 | grdxt_t; |
---|
56 | |
---|
57 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
58 | // Local access functions |
---|
59 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
60 | |
---|
61 | /******************************************************************************************* |
---|
62 | * This function initialises the radix-tree descriptor, |
---|
63 | * It must be called by a local thread. |
---|
64 | * and allocates memory for the first level array of pointers. |
---|
65 | ******************************************************************************************* |
---|
66 | * @ rt : pointer on the radix-tree descriptor. |
---|
67 | * @ ix1_width : number of bits in ix1 field |
---|
68 | * @ ix2_width : number of bits in ix2 field |
---|
69 | * @ ix3_width : number of bits in ix3 field |
---|
70 | * @ returns 0 if success / returns ENOMEM if no more memory. |
---|
71 | ******************************************************************************************/ |
---|
72 | error_t grdxt_init( grdxt_t * rt, |
---|
73 | uint32_t ix1_width, |
---|
74 | uint32_t ix2_width, |
---|
75 | uint32_t ix3_width ); |
---|
76 | |
---|
77 | /******************************************************************************************* |
---|
78 | * This function releases all memory allocated to the radix-tree infrastructure. |
---|
79 | * It must be called by a local thread. |
---|
80 | * A warning message is printed on the kernel TXT0 if the radix tree is not empty. |
---|
81 | ******************************************************************************************* |
---|
82 | * @ rt : pointer on the radix-tree descriptor. |
---|
83 | ******************************************************************************************/ |
---|
84 | void grdxt_destroy( grdxt_t * rt ); |
---|
85 | |
---|
86 | /******************************************************************************************* |
---|
87 | * This function insert a new item in the radix-tree. |
---|
88 | * It must be called by a local thread. |
---|
89 | * It dynamically allocates memory for new second and third level arrays if required. |
---|
90 | ******************************************************************************************* |
---|
91 | * @ rt : pointer on the radix-tree descriptor. |
---|
92 | * @ key : key value. |
---|
93 | * @ value : pointer on item to be registered in radix-tree. |
---|
94 | * @ returns 0 if success / returns -1 if no memory, or illegal key. |
---|
95 | ******************************************************************************************/ |
---|
96 | error_t grdxt_insert( grdxt_t * rt, |
---|
97 | uint32_t key, |
---|
98 | void * value ); |
---|
99 | |
---|
100 | /******************************************************************************************* |
---|
101 | * This function removes an item identified by its key from the radix tree, |
---|
102 | * It must be called by a local thread. |
---|
103 | * and returns a pointer on the removed item. No memory is released. |
---|
104 | ******************************************************************************************* |
---|
105 | * @ rt : pointer on the radix-tree descriptor. |
---|
106 | * @ key : key value. |
---|
107 | * @ returns pointer on removed item if success / returns NULL if failure. |
---|
108 | ******************************************************************************************/ |
---|
109 | void * grdxt_remove( grdxt_t * rt, |
---|
110 | uint32_t key ); |
---|
111 | |
---|
112 | /******************************************************************************************* |
---|
113 | * This function returns to a local client, a local pointer on the item identified |
---|
114 | * It must be called by a local thread. |
---|
115 | * by the <key> argument, from the radix tree identified by the <rt> local pointer. |
---|
116 | ******************************************************************************************* |
---|
117 | * @ rt : local pointer on the radix-tree descriptor. |
---|
118 | * @ key : key value. |
---|
119 | * @ returns a local pointer on found item if success / returns NULL if failure. |
---|
120 | ******************************************************************************************/ |
---|
121 | void * grdxt_lookup( grdxt_t * rt, |
---|
122 | uint32_t key ); |
---|
123 | |
---|
124 | /******************************************************************************************* |
---|
125 | * This function scan all radix-tree entries in increasing key order, starting from |
---|
126 | * It must be called by a local thread. |
---|
127 | * the value defined by the <key> argument, and return a pointer on the first valid |
---|
128 | * registered item, and the found item key value. |
---|
129 | ******************************************************************************************* |
---|
130 | * @ rt : pointer on the radix-tree descriptor. |
---|
131 | * @ start_key : key starting value for the scan. |
---|
132 | * @ found_key : [out] buffer for found key value. |
---|
133 | * @ return pointer on first valid item if found / return NULL if not found. |
---|
134 | ******************************************************************************************/ |
---|
135 | void * grdxt_get_first( grdxt_t * rt, |
---|
136 | uint32_t start_key, |
---|
137 | uint32_t * found_key ); |
---|
138 | |
---|
139 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
140 | // Remote access functions |
---|
141 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
142 | |
---|
143 | /******************************************************************************************* |
---|
144 | * This function insert a new item in a - possibly remote - radix tree. |
---|
145 | * It dynamically allocates memory for new second and third level arrays if required. |
---|
146 | ******************************************************************************************* |
---|
147 | * @ rt_xp : extended pointer on the radix-tree descriptor. |
---|
148 | * @ key : key value. |
---|
149 | * @ value : pointer on item to be registered in radix-tree. |
---|
150 | * @ returns 0 if success / returns -1 if no memory, or illegal key. |
---|
151 | ******************************************************************************************/ |
---|
152 | error_t grdxt_remote_insert( xptr_t rt_xp, |
---|
153 | uint32_t key, |
---|
154 | void * value ); |
---|
155 | |
---|
156 | /******************************************************************************************* |
---|
157 | * This function removes an item identified by its key from a - possibly remote - radix |
---|
158 | * tree, and returns a local pointer on the removed item. No memory is released. |
---|
159 | ******************************************************************************************* |
---|
160 | * @ rt_xp : pointer on the radix-tree descriptor. |
---|
161 | * @ key : key value. |
---|
162 | * @ returns local pointer on removed item if success / returns NULL if failure. |
---|
163 | ******************************************************************************************/ |
---|
164 | void * grdxt_remote_remove( xptr_t rt_xp, |
---|
165 | uint32_t key ); |
---|
166 | |
---|
167 | /******************************************************************************************* |
---|
168 | * This function returns to a - possibly remote - client, an extended pointer |
---|
169 | * on the item identified by the <key> argument, from the radix tree identified by |
---|
170 | * the <rt_xp> remote pointer. |
---|
171 | ******************************************************************************************* |
---|
172 | * @ rt_xp : extended pointer on the radix-tree descriptor. |
---|
173 | * @ key : key value. |
---|
174 | * @ returns an extended pointer on found item if success / returns XPTR_NULL if failure. |
---|
175 | ******************************************************************************************/ |
---|
176 | xptr_t grdxt_remote_lookup( xptr_t rt_xp, |
---|
177 | uint32_t key ); |
---|
178 | |
---|
179 | /******************************************************************************************* |
---|
180 | * This function displays the current content of a possibly remote radix_tree. |
---|
181 | ******************************************************************************************* |
---|
182 | * @ rt : extended pointer on the radix-tree descriptor. |
---|
183 | * @ string : radix tree identifier. |
---|
184 | ******************************************************************************************/ |
---|
185 | void grdxt_remote_display( xptr_t rt_xp, |
---|
186 | char * string ); |
---|
187 | |
---|
188 | #endif /* _GRDXT_H_ */ |
---|
189 | |
---|