Debian Codegraph @

src/OVAL/probes/probe/ncache.h

raw symbols SCIP
1 /*
2 * Copyright 2011 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * Daniel Kopecek <[email protected]>
21 */
22 #ifndef PROBE_NCACHE_H
23 #define PROBE_NCACHE_H
24
25 #include <stddef.h>
26 #include <pthread.h>
27 #include <sexp.h>
28
29 #define PROBE_NCACHE_INIT_SIZE 24
30 #define PROBE_NCACHE_ADD_SIZE 8
31
32 /**
33 * Element name cache structure. This structure contains an array
34 * of cached string S-exps representing the names of elements.
35 */
36 typedef struct {
37 pthread_rwlock_t lock; /**< pthread read-write lock */
38 SEXP_t **name; /**< array of S-exp refs */
39 size_t real; /**< number of cached names */
40 size_t size; /**< pre-allocated size */
41 } probe_ncache_t;
42
43 /**
44 * Create new element name cache
45 * @return an empty element name cache
46 */
47 probe_ncache_t *probe_ncache_new (void);
48
49 /**
50 * Free memory used by the element name cache.
51 * The S-exp objects stored in the cache are
52 * also freed. However, if they are referenced
53 * somewhere else, the memory won't be freed, just
54 * the reference count will be decremented.
55 * @param cache the cache to be freed
56 */
57 void probe_ncache_free (probe_ncache_t *cache);
58
59 /**
60 * Mark memory used by the element name cache as
61 * free, effectively emptying the cache (but not
62 * altering the amount of memomory allocated for it).
63 * The S-exp objects stored in the cache are
64 * also freed. However, if they are referenced
65 * somewhere else, the memory won't be freed, just
66 * the reference count will be decremented.
67 * @param cache the cache to be emptied
68 */
69 void probe_ncache_clear (probe_ncache_t *cache);
70
71 /**
72 * Add a name to the cache. This will create a new S-exp
73 * object and return a reference to it. Reference count
74 * of such object will be 2 because the cache hold it's
75 * own reference to the object.
76 * @param cache element name cache
77 * @param name name string
78 * @return S-exp reference to the name string
79 */
80 SEXP_t *probe_ncache_add (probe_ncache_t *cache, const char *name);
81
82 /**
83 * Get a reference to an already cached S-exp object. If the
84 * object is not found in the cache, it won't be created and
85 * NULL will be returned to the caller.
86 * @param cache element name cache
87 * @param name name string
88 * @return S-exp reference to the name string or NULL if not found
89 */
90 SEXP_t *probe_ncache_get (probe_ncache_t *cache, const char *name);
91
92 /**
93 * Get a reference to a cached S-exp object. If the object is
94 * not found in the cache, it will be created and the reference
95 * this newly created object will be returned to the caller.
96 * @param cache element name cache
97 * @param name name string
98 * @return S-exp reference to the name string
99 */
100 SEXP_t *probe_ncache_ref (probe_ncache_t *cache, const char *name);
101
102 #endif /* PROBE_NCACHE_H */