00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #pragma once
00025 #ifndef PROBE_CACHE_H
00026 #define PROBE_CACHE_H
00027
00028 #include <stdbool.h>
00029 #include <pthread.h>
00030 #include <sexp-types.h>
00031 #include <SEAP/generic/redblack.h>
00032 #include <../../common/util.h>
00033
00034 OSCAP_HIDDEN_START;
00035
00036 DEFRBTREE(pcache, SEXP_t * id;
00037 SEXP_t * item);
00038
00039 typedef struct {
00040 TREETYPE(pcache) tree;
00041 pthread_rwlock_t lock;
00042 } pcache_t;
00043
00044 static inline int pcache_rlock(pcache_t * c)
00045 {
00046 return (pthread_rwlock_rdlock(&c->lock) == 0 ? 0 : -1);
00047 }
00048
00049 static inline int pcache_wlock(pcache_t * c)
00050 {
00051 return (pthread_rwlock_wrlock(&c->lock) == 0 ? 0 : -1);
00052 }
00053
00054 static inline int pcache_wunlock(pcache_t * c)
00055 {
00056 return (pthread_rwlock_unlock(&c->lock) == 0 ? 0 : -1);
00057 }
00058
00059 #define pcache_runlock(c) pcache_wunlock(c)
00060 #define with_pcache_rlocked(c) for (bool __rlk__ = (pcache_rlock (c) == 0 ? true : false); __rlk__; __rlk__ = (pcache_runlock (c) == 0 ? false : abort(), false))
00061 #define with_pcache_wlocked(c) for (bool __wlk__ = (pcache_wlock (c) == 0 ? true : false); __wlk__; __wlk__ = (pcache_wunlock (c) == 0 ? false : abort(), false))
00062
00063 pcache_t *pcache_new(void);
00064 void pcache_free(pcache_t * cache);
00065
00066 int pcache_sexp_add(pcache_t * cache, const SEXP_t * id, SEXP_t * item);
00067 int pcache_cstr_add(pcache_t * cache, const char *id, SEXP_t * item);
00068
00069 int pcache_sexp_del(pcache_t * cache, const SEXP_t * id);
00070 int pcache_cstr_del(pcache_t * cache, const char *id);
00071
00072 SEXP_t *pcache_sexp_get(pcache_t * cache, const SEXP_t * id);
00073 SEXP_t *pcache_cstr_get(pcache_t * cache, const char *id);
00074
00075 OSCAP_HIDDEN_END;
00076
00077 #endif