LCOV - code coverage report
Current view: top level - lib - eu-search.h (source / functions) Coverage Total Hit
Test: elfutils-0.194 Lines: 66.7 % 6 4
Test Date: 2025-10-24 21:43:55 Functions: - 0 0
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       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                 :     1128106 : eu_tsearch_nolock (const void *key, search_tree *tree,
      58                 :             :                    int (*compare)(const void *, const void *))
      59                 :             : {
      60                 :     1128106 :   return tsearch (key, &tree->root, compare);
      61                 :             : }
      62                 :             : 
      63                 :             : /* Search TREE for KEY.  No locking is performed.  */
      64                 :             : static inline void *
      65                 :     1473358 : eu_tfind_nolock (const void *key, search_tree *tree,
      66                 :             :                  int (*compare)(const void *, const void *))
      67                 :             : {
      68                 :     1473358 :   return tfind (key, &tree->root, compare);
      69                 :             : }
      70                 :             : 
      71                 :             : /* Delete key from TREE.  No locking is performed.  */
      72                 :             : static inline void *
      73                 :           0 : eu_tdelete_nolock (const void *key, search_tree *tree,
      74                 :             :                    int (*compare)(const void *, const void *))
      75                 :             : {
      76                 :           0 :   return tdelete (key, &tree->root, compare);
      77                 :             : }
      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
        

Generated by: LCOV version 2.0-1