/src/elfutils/lib/eu-search.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Calls for thread-safe tsearch/tfind |
2 | | Copyright (C) 2023 Rice University |
3 | | This file is part of elfutils. |
4 | | |
5 | | This file is free software; you can redistribute it and/or modify |
6 | | it under the terms of either |
7 | | |
8 | | * the GNU Lesser General Public License as published by the Free |
9 | | Software Foundation; either version 3 of the License, or (at |
10 | | your option) any later version |
11 | | |
12 | | or |
13 | | |
14 | | * the GNU General Public License as published by the Free |
15 | | Software Foundation; either version 2 of the License, or (at |
16 | | your option) any later version |
17 | | |
18 | | or both in parallel, as here. |
19 | | |
20 | | elfutils is distributed in the hope that it will be useful, but |
21 | | WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
23 | | General Public License for more details. |
24 | | |
25 | | You should have received copies of the GNU General Public License and |
26 | | the GNU Lesser General Public License along with this program. If |
27 | | not, see <http://www.gnu.org/licenses/>. */ |
28 | | |
29 | | #ifndef EU_SEARCH_H |
30 | | #define EU_SEARCH_H 1 |
31 | | |
32 | | #include <stdlib.h> |
33 | | #include <search.h> |
34 | | #include <locks.h> |
35 | | |
36 | | typedef struct |
37 | | { |
38 | | void *root; |
39 | | rwlock_define (, lock); |
40 | | } search_tree; |
41 | | |
42 | | /* Search TREE for KEY and add KEY if not found. Synchronized using |
43 | | TREE's lock. */ |
44 | | extern void *eu_tsearch (const void *key, search_tree *tree, |
45 | | int (*compare)(const void *, const void *)); |
46 | | |
47 | | /* Search TREE for KEY. Synchronized with TREE's lock. */ |
48 | | extern void *eu_tfind (const void *key, search_tree *tree, |
49 | | int (*compare)(const void *, const void *)); |
50 | | |
51 | | /* Delete key from TREE. Synchronized with TREE's lock. */ |
52 | | extern void *eu_tdelete (const void *key, search_tree *tree, |
53 | | int (*compare)(const void *, const void *)); |
54 | | |
55 | | /* Search TREE for KEY and add KEY if not found. No locking is performed. */ |
56 | | static inline void * |
57 | | eu_tsearch_nolock (const void *key, search_tree *tree, |
58 | | int (*compare)(const void *, const void *)) |
59 | 0 | { |
60 | 0 | return tsearch (key, &tree->root, compare); |
61 | 0 | } Unexecuted instantiation: elf_version.c:eu_tsearch_nolock Unexecuted instantiation: elf_error.c:eu_tsearch_nolock Unexecuted instantiation: elf_begin.c:eu_tsearch_nolock Unexecuted instantiation: elf_end.c:eu_tsearch_nolock Unexecuted instantiation: elf_rawfile.c:eu_tsearch_nolock Unexecuted instantiation: elf_readall.c:eu_tsearch_nolock Unexecuted instantiation: elf_nextscn.c:eu_tsearch_nolock Unexecuted instantiation: gelf_getshdr.c:eu_tsearch_nolock Unexecuted instantiation: elf_strptr.c:eu_tsearch_nolock Unexecuted instantiation: elf_getdata.c:eu_tsearch_nolock Unexecuted instantiation: elf_getshdrstrndx.c:eu_tsearch_nolock Unexecuted instantiation: elf_compress.c:eu_tsearch_nolock Unexecuted instantiation: elf_compress_gnu.c:eu_tsearch_nolock Unexecuted instantiation: eu-search.c:eu_tsearch_nolock Unexecuted instantiation: gelf_fsize.c:eu_tsearch_nolock Unexecuted instantiation: gelf_xlate.c:eu_tsearch_nolock Unexecuted instantiation: gelf_getehdr.c:eu_tsearch_nolock Unexecuted instantiation: elf32_getshdr.c:eu_tsearch_nolock Unexecuted instantiation: elf64_getshdr.c:eu_tsearch_nolock Unexecuted instantiation: gelf_xlatetof.c:eu_tsearch_nolock Unexecuted instantiation: elf_getshdrnum.c:eu_tsearch_nolock Unexecuted instantiation: gelf_getchdr.c:eu_tsearch_nolock Unexecuted instantiation: elf32_xlatetof.c:eu_tsearch_nolock Unexecuted instantiation: elf64_xlatetof.c:eu_tsearch_nolock Unexecuted instantiation: elf32_getchdr.c:eu_tsearch_nolock Unexecuted instantiation: elf64_getchdr.c:eu_tsearch_nolock |
62 | | |
63 | | /* Search TREE for KEY. No locking is performed. */ |
64 | | static inline void * |
65 | | eu_tfind_nolock (const void *key, search_tree *tree, |
66 | | int (*compare)(const void *, const void *)) |
67 | 0 | { |
68 | 0 | return tfind (key, &tree->root, compare); |
69 | 0 | } Unexecuted instantiation: elf_version.c:eu_tfind_nolock Unexecuted instantiation: elf_error.c:eu_tfind_nolock Unexecuted instantiation: elf_begin.c:eu_tfind_nolock Unexecuted instantiation: elf_end.c:eu_tfind_nolock Unexecuted instantiation: elf_rawfile.c:eu_tfind_nolock Unexecuted instantiation: elf_readall.c:eu_tfind_nolock Unexecuted instantiation: elf_nextscn.c:eu_tfind_nolock Unexecuted instantiation: gelf_getshdr.c:eu_tfind_nolock Unexecuted instantiation: elf_strptr.c:eu_tfind_nolock Unexecuted instantiation: elf_getdata.c:eu_tfind_nolock Unexecuted instantiation: elf_getshdrstrndx.c:eu_tfind_nolock Unexecuted instantiation: elf_compress.c:eu_tfind_nolock Unexecuted instantiation: elf_compress_gnu.c:eu_tfind_nolock Unexecuted instantiation: eu-search.c:eu_tfind_nolock Unexecuted instantiation: gelf_fsize.c:eu_tfind_nolock Unexecuted instantiation: gelf_xlate.c:eu_tfind_nolock Unexecuted instantiation: gelf_getehdr.c:eu_tfind_nolock Unexecuted instantiation: elf32_getshdr.c:eu_tfind_nolock Unexecuted instantiation: elf64_getshdr.c:eu_tfind_nolock Unexecuted instantiation: gelf_xlatetof.c:eu_tfind_nolock Unexecuted instantiation: elf_getshdrnum.c:eu_tfind_nolock Unexecuted instantiation: gelf_getchdr.c:eu_tfind_nolock Unexecuted instantiation: elf32_xlatetof.c:eu_tfind_nolock Unexecuted instantiation: elf64_xlatetof.c:eu_tfind_nolock Unexecuted instantiation: elf32_getchdr.c:eu_tfind_nolock Unexecuted instantiation: elf64_getchdr.c:eu_tfind_nolock |
70 | | |
71 | | /* Delete key from TREE. No locking is performed. */ |
72 | | static inline void * |
73 | | eu_tdelete_nolock (const void *key, search_tree *tree, |
74 | | int (*compare)(const void *, const void *)) |
75 | 0 | { |
76 | 0 | return tdelete (key, &tree->root, compare); |
77 | 0 | } Unexecuted instantiation: elf_version.c:eu_tdelete_nolock Unexecuted instantiation: elf_error.c:eu_tdelete_nolock Unexecuted instantiation: elf_begin.c:eu_tdelete_nolock Unexecuted instantiation: elf_end.c:eu_tdelete_nolock Unexecuted instantiation: elf_rawfile.c:eu_tdelete_nolock Unexecuted instantiation: elf_readall.c:eu_tdelete_nolock Unexecuted instantiation: elf_nextscn.c:eu_tdelete_nolock Unexecuted instantiation: gelf_getshdr.c:eu_tdelete_nolock Unexecuted instantiation: elf_strptr.c:eu_tdelete_nolock Unexecuted instantiation: elf_getdata.c:eu_tdelete_nolock Unexecuted instantiation: elf_getshdrstrndx.c:eu_tdelete_nolock Unexecuted instantiation: elf_compress.c:eu_tdelete_nolock Unexecuted instantiation: elf_compress_gnu.c:eu_tdelete_nolock Unexecuted instantiation: eu-search.c:eu_tdelete_nolock Unexecuted instantiation: gelf_fsize.c:eu_tdelete_nolock Unexecuted instantiation: gelf_xlate.c:eu_tdelete_nolock Unexecuted instantiation: gelf_getehdr.c:eu_tdelete_nolock Unexecuted instantiation: elf32_getshdr.c:eu_tdelete_nolock Unexecuted instantiation: elf64_getshdr.c:eu_tdelete_nolock Unexecuted instantiation: gelf_xlatetof.c:eu_tdelete_nolock Unexecuted instantiation: elf_getshdrnum.c:eu_tdelete_nolock Unexecuted instantiation: gelf_getchdr.c:eu_tdelete_nolock Unexecuted instantiation: elf32_xlatetof.c:eu_tdelete_nolock Unexecuted instantiation: elf64_xlatetof.c:eu_tdelete_nolock Unexecuted instantiation: elf32_getchdr.c:eu_tdelete_nolock Unexecuted instantiation: elf64_getchdr.c:eu_tdelete_nolock |
78 | | |
79 | | /* Free all nodes from TREE. */ |
80 | | void eu_tdestroy (search_tree *tree, void (*free_node)(void *)); |
81 | | |
82 | | /* Initialize TREE's root and lock. */ |
83 | | void eu_search_tree_init (search_tree *tree); |
84 | | |
85 | | /* Free all nodes from TREE as well as TREE's lock. */ |
86 | | void eu_search_tree_fini (search_tree *tree, void (*free_node)(void *)); |
87 | | |
88 | | #endif |