/home/pvrabec/project/openscap/openscap-0.6.0/src/OVAL/probes/encache.c File Reference

element name cache API implementation More...

#include <stdlib.h>
#include <string.h>
#include <sexp.h>
#include "encache.h"
#include "alloc.h"
#include "common/bfind.h"
#include "common/assume.h"

Defines

#define ENCACHE_RLOCK(c, r)
 Lock cache for reading.
#define ENCACHE_RUNLOCK(c)
 Unlock cache which was previously locked for reading.
#define ENCACHE_WLOCK(c, r)
 Lock cache for writing.
#define ENCACHE_WUNLOCK(c)   ENCACHE_RUNLOCK(c)
 Unlock cache which was previously locked for writing.

Functions

encache_tencache_new (void)
 Create new element name cache.
void encache_free (encache_t *cache)
 Free memory used by the element name cache.
SEXP_tencache_add (encache_t *cache, const char *name)
 Add a name to the cache.
SEXP_tencache_get (encache_t *cache, const char *name)
 Get a reference to an already cached S-exp object.
SEXP_tencache_ref (encache_t *cache, const char *name)
 Get a reference to a cached S-exp object.

Detailed Description

element name cache API implementation

Author:
"Daniel Kopecek" <dkopecek@redhat.com>

Define Documentation

#define ENCACHE_RLOCK ( c,
 ) 
Value:
do {                                                    \
                if (pthread_rwlock_rdlock (&(c)->lock) != 0)    \
                        return (r);                             \
        } while (0)

Lock cache for reading.

Parameters:
c element name cache
r return value on failure
#define ENCACHE_RUNLOCK (  ) 
Value:
do {                                                    \
                if (pthread_rwlock_unlock (&(c)->lock) != 0)    \
                        abort ();                               \
        } while (0)

Unlock cache which was previously locked for reading.

Parameters:
c element name cache
Returns:
this function calls abort(3) if it is unable to unlock the cache so as to prevent a deadlock.
#define ENCACHE_WLOCK ( c,
 ) 
Value:
do {                                                    \
                if (pthread_rwlock_wrlock (&(c)->lock) != 0)    \
                        return (r);                             \
        } while (0)

Lock cache for writing.

Parameters:
c element name cache
r return value on failure
#define ENCACHE_WUNLOCK (  )     ENCACHE_RUNLOCK(c)

Unlock cache which was previously locked for writing.

Parameters:
c element name cache
Returns:
this function calls abort(3) if it is unable to unlock the cache so as to prevent a deadlock.

Function Documentation

SEXP_t* encache_add ( encache_t cache,
const char *  name 
)

Add a name to the cache.

This will create a new S-exp object and return a reference to it. Reference count of such object will be 2 because the cache hold it's own reference to the object.

Parameters:
cache element name cache
name name string
Returns:
S-exp reference to the name string
void encache_free ( encache_t cache  ) 

Free memory used by the element name cache.

The S-exp objects stored in the cache are also freed. However, if they are referenced somewhere else, the memory won't be freed, just the reference count will be decremented.

Parameters:
cache the cache to be freed
SEXP_t* encache_get ( encache_t cache,
const char *  name 
)

Get a reference to an already cached S-exp object.

If the object is not found in the cache, it won't be created and NULL will be returned to the caller.

Parameters:
cache element name cache
name name string
Returns:
S-exp reference to the name string or NULL if not found
encache_t* encache_new ( void   ) 

Create new element name cache.

Returns:
an empty element name cache
SEXP_t* encache_ref ( encache_t cache,
const char *  name 
)

Get a reference to a cached S-exp object.

If the object is not found in the cache, it will be created and the reference this newly created object will be returned to the caller.

Parameters:
cache element name cache
name name string
Returns:
S-exp reference to the name string

Generated on 14 Jul 2010 for Open SCAP Library by  doxygen 1.6.1