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_t * | encache_new (void) |
Create new element name cache. | |
void | encache_free (encache_t *cache) |
Free memory used by the element name cache. | |
SEXP_t * | encache_add (encache_t *cache, const char *name) |
Add a name to the cache. | |
SEXP_t * | encache_get (encache_t *cache, const char *name) |
Get a reference to an already cached S-exp object. | |
SEXP_t * | encache_ref (encache_t *cache, const char *name) |
Get a reference to a cached S-exp object. |
element name cache API implementation
#define ENCACHE_RLOCK | ( | c, | |||
r | ) |
do { \ if (pthread_rwlock_rdlock (&(c)->lock) != 0) \ return (r); \ } while (0)
Lock cache for reading.
c | element name cache | |
r | return value on failure |
#define ENCACHE_RUNLOCK | ( | c | ) |
do { \ if (pthread_rwlock_unlock (&(c)->lock) != 0) \ abort (); \ } while (0)
Unlock cache which was previously locked for reading.
c | element name cache |
#define ENCACHE_WLOCK | ( | c, | |||
r | ) |
do { \ if (pthread_rwlock_wrlock (&(c)->lock) != 0) \ return (r); \ } while (0)
Lock cache for writing.
c | element name cache | |
r | return value on failure |
#define ENCACHE_WUNLOCK | ( | c | ) | ENCACHE_RUNLOCK(c) |
Unlock cache which was previously locked for writing.
c | element name cache |
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.
cache | element name cache | |
name | 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.
cache | the cache to be freed |
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.
cache | element name cache | |
name | name string |
encache_t* encache_new | ( | void | ) |
Create new element name cache.
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.
cache | element name cache | |
name | name string |