| @@ -1,13 +1,14 @@ | | | @@ -1,13 +1,14 @@ |
| | | 1 | .\" $NetBSD: thmap.9,v 1.2 2019/08/28 22:11:25 wiz Exp $ |
1 | .\" | | 2 | .\" |
2 | .\" Copyright (c) 2018 Mindaugas Rasiukevicius <rmind at noxt eu> | | 3 | .\" Copyright (c) 2018 Mindaugas Rasiukevicius <rmind at noxt eu> |
3 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
4 | .\" | | 5 | .\" |
5 | .\" Redistribution and use in source and binary forms, with or without | | 6 | .\" Redistribution and use in source and binary forms, with or without |
6 | .\" modification, are permitted provided that the following conditions | | 7 | .\" modification, are permitted provided that the following conditions |
7 | .\" are met: | | 8 | .\" are met: |
8 | .\" 1. Redistributions of source code must retain the above copyright | | 9 | .\" 1. Redistributions of source code must retain the above copyright |
9 | .\" notice, this list of conditions and the following disclaimer. | | 10 | .\" notice, this list of conditions and the following disclaimer. |
10 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
11 | .\" notice, this list of conditions and the following disclaimer in the | | 12 | .\" notice, this list of conditions and the following disclaimer in the |
12 | .\" documentation and/or other materials provided with the distribution. | | 13 | .\" documentation and/or other materials provided with the distribution. |
13 | .\" | | 14 | .\" |
| @@ -185,52 +186,52 @@ Return 0 on success and \-1 on failure ( | | | @@ -185,52 +186,52 @@ Return 0 on success and \-1 on failure ( |
185 | Get the root node address. | | 186 | Get the root node address. |
186 | The returned address will be relative to the base address. | | 187 | The returned address will be relative to the base address. |
187 | .El | | 188 | .El |
188 | .\" --- | | 189 | .\" --- |
189 | .Pp | | 190 | .Pp |
190 | Members of | | 191 | Members of |
191 | .Vt thmap_ops_t | | 192 | .Vt thmap_ops_t |
192 | are | | 193 | are |
193 | .Bd -literal | | 194 | .Bd -literal |
194 | uintptr_t (*alloc)(size_t len); | | 195 | uintptr_t (*alloc)(size_t len); |
195 | void (*free)(uintptr_t addr, size_t len); | | 196 | void (*free)(uintptr_t addr, size_t len); |
196 | .Ed | | 197 | .Ed |
197 | .\" ----- | | 198 | .\" ----- |
198 | .Sh CAVEATS | | | |
199 | The implementation uses pointer tagging and atomic operations. | | | |
200 | This requires the base address and the allocations to provide at least word | | | |
201 | alignment. | | | |
202 | .Pp | | | |
203 | While the | | | |
204 | .Dv NULL | | | |
205 | values may be inserted, | | | |
206 | .Fn thmap_get | | | |
207 | and | | | |
208 | .Fn thmap_del | | | |
209 | cannot indicate whether the key was not found or a key with a | | | |
210 | .Dv NULL | | | |
211 | value was found. | | | |
212 | If the caller needs to indicate an "empty" value, it can use a | | | |
213 | special pointer value, such as | | | |
214 | .Li (void *)(uintptr_t)0x1 . | | | |
215 | .\" ----- | | | |
216 | .Sh EXAMPLES | | 199 | .Sh EXAMPLES |
217 | Simple case backed by | | 200 | Simple case backed by |
218 | .Xr malloc 3 , | | 201 | .Xr malloc 3 , |
219 | which could be used in multi-threaded environment: | | 202 | which could be used in multi-threaded environment: |
220 | .Bd -literal | | 203 | .Bd -literal |
221 | thmap_t *kvmap; | | 204 | thmap_t *kvmap; |
222 | struct obj *obj; | | 205 | struct obj *obj; |
223 | | | 206 | |
224 | kvmap = thmap_create(0, NULL); | | 207 | kvmap = thmap_create(0, NULL); |
225 | assert(kvmap != NULL); | | 208 | assert(kvmap != NULL); |
226 | ... | | 209 | ... |
227 | obj = obj_create(); | | 210 | obj = obj_create(); |
228 | thmap_put(kvmap, "test", sizeof("test") - 1, obj); | | 211 | thmap_put(kvmap, "test", sizeof("test") - 1, obj); |
229 | ... | | 212 | ... |
230 | obj = thmap_get(kvmap, "test", sizeof("test") - 1); | | 213 | obj = thmap_get(kvmap, "test", sizeof("test") - 1); |
231 | ... | | 214 | ... |
232 | thmap_destroy(kvmap); | | 215 | thmap_destroy(kvmap); |
233 | .Ed | | 216 | .Ed |
234 | .\" ----- | | 217 | .\" ----- |
235 | .Sh AUTHORS | | 218 | .Sh AUTHORS |
236 | .An Mindaugas Rasiukevicius Aq Mt rmind@noxt.eu | | 219 | .An Mindaugas Rasiukevicius Aq Mt rmind@noxt.eu |
| | | 220 | .Sh CAVEATS |
| | | 221 | The implementation uses pointer tagging and atomic operations. |
| | | 222 | This requires the base address and the allocations to provide at least word |
| | | 223 | alignment. |
| | | 224 | .Pp |
| | | 225 | While the |
| | | 226 | .Dv NULL |
| | | 227 | values may be inserted, |
| | | 228 | .Fn thmap_get |
| | | 229 | and |
| | | 230 | .Fn thmap_del |
| | | 231 | cannot indicate whether the key was not found or a key with a |
| | | 232 | .Dv NULL |
| | | 233 | value was found. |
| | | 234 | If the caller needs to indicate an "empty" value, it can use a |
| | | 235 | special pointer value, such as |
| | | 236 | .Li (void *)(uintptr_t)0x1 . |
| | | 237 | .\" ----- |