12 #define IS_ACTIVE_ELT(elt) (c->locks[elt] != 2) 13 #define IS_NOT_ACTIVE_ELT(elt) (c->locks[elt] == 2) 14 #define IS_LOCKED_ELT(elt) (c->locks[elt] == 1) 15 #define IS_UNLOCKED_ELT(elt) (c->locks[elt] == 0) 16 #define IS_NOT_IN_QUEUE_ELT(elt) (IS_LOCKED_ELT (elt)) 17 #define IS_IN_QUEUE_ELT(elt) (! IS_NOT_IN_QUEUE_ELT (elt)) 19 #define DEACTIVATE_ELT(elt) ((IS_LOCKED_ELT(elt) ? \ 20 (c->nofUnlocked)++ : (0)), \ 22 #define LOCK_ELT(elt) ((IS_LOCKED_ELT(elt) ? \ 23 (0) : (c->nofUnlocked)--), \ 25 #define UNLOCK_ELT(elt) ((IS_LOCKED_ELT(elt) ? \ 26 (c->nofUnlocked)++ : (0)), \ 29 #define ONE_UNLOCKED_ELT_ONLY (c->first == c->last) 30 #define ARE_MIN_UNLOCKED (c->nofUnlocked <= c->minUnlocked) 38 for (i = 0; i < c->
nofElts; i++) {
58 static int cache_dummy_fun(
int tileIndex,
const void *tileBuf,
void *map)
89 int (*eltRemoveFun) (),
void *eltRemoveFunData,
90 int (*eltLoadFun) (),
void *eltLoadFunData)
97 Rast3d_error(
"Rast3d_cache_new: error in Rast3d_malloc");
115 Rast3d_error(
"Rast3d_cache_new: error in Rast3d_malloc");
119 for(i = 0; i < tmp->
nofElts; i++)
130 Rast3d_error(
"Rast3d_cache_new: error in Rast3d_cache_hash_new");
143 void *eltRemoveFunData)
153 void *eltLoadFunData)
162 read_fn * eltLoadFun,
void *eltLoadFunData)
165 cache_dummy_fun,
NULL, eltLoadFun, eltLoadFunData);
175 if (index == c->
first)
177 if (index == c->
last)
180 if (c->
next[index] != -1)
182 if (c->
prev[index] != -1)
185 c->
next[index] = c->
prev[index] = -1;
190 static void cache_queue_enqueue(
RASTER3D_cache * c,
int left,
int index)
195 if (c->
first == -1) {
215 c->
prev[index] = left;
217 if (c->
next[left] == -1) {
218 c->
next[left] = index;
226 c->
next[left] = index;
237 cache_queue_dequeue(c, c->
first);
246 cache_queue_enqueue(c, c->
last, index);
253 cache_queue_enqueue(c, -1, index);
283 cache_queue_dequeue(c, index);
296 cache_queue_dequeue(c, index);
315 cache_queue_append(c, index);
327 for (index = 0; index < c->
nofElts; index++)
330 Rast3d_error(
"Rast3d_cache_unlock_all: error in Rast3d_cache_unlock");
343 for (index = 0; index < c->
nofElts; index++)
379 Rast3d_error(
"Rast3d_cache_deactivate_elt : name not in cache");
387 cache_queue_dequeue(c, index);
394 Rast3d_error(
"cache_remove_elt: error in c->eltRemoveFun");
398 cache_queue_preppend(c, index);
410 if (!cache_remove_elt(c, name, 0)) {
411 Rast3d_error(
"Rast3d_cache_remove_elt: error in cache_remove_elt");
422 if (!cache_remove_elt(c, name, 1)) {
423 Rast3d_error(
"Rast3d_cache_flush: error in cache_remove_elt");
436 for (index = 0; index < c->
nofElts; index++)
440 (
"Rast3d_cache_remove_all: error in Rast3d_cache_remove_elt");
453 for (index = 0; index < c->
nofElts; index++)
456 Rast3d_error(
"Rast3d_cache_flush_all: error in Rast3d_cache_flush");
467 int index, oldName, doUnlock;
482 oldName = c->
names[index];
486 Rast3d_error(
"Rast3d_cache_elt_ptr: error in c->eltRemoveFun");
501 Rast3d_error(
"Rast3d_cache_elt_ptr: error in Rast3d_cache_unlock");
506 Rast3d_error(
"Rast3d_cache_elt_ptr: error in c->eltLoadFun");
518 Rast3d_error(
"Rast3d_cache_load: error in Rast3d_cache_elt_ptr");
533 Rast3d_error(
"Rast3d_cache_get_elt: error in Rast3d_cache_elt_ptr");
550 Rast3d_error(
"Rast3d_cache_put_elt: error in Rast3d_cache_elt_ptr");
577 printf(
"\n--------------------------------\n");
578 for (i = 0; i < c->
nofElts; i++) {
579 printf(
"elt %d: ", i);
587 printf(
"name %d val %d %s\n", c->
names[i], a[17],
591 printf(
"\n--------------------------------\n");
599 static int cache_test_flush_fun(
int name,
const void *eltPtr,
void *data)
601 printf(
"flushing name %d value %d\n", name, ((
const int *)eltPtr)[17]);
613 } cache_test_data_type;
615 static int cache_test_load_fun(
int name,
void *eltPtr,
void *data)
619 printf(
"loading name %d value %d\n", name,
620 ((cache_test_data_type *) data)->value[17]);
622 src = ((cache_test_data_type *) data)->value;
623 memcpy(eltPtr, src, ((cache_test_data_type *) data)->size);
630 static cache_test_data_type ctd;
632 static void cache_test_add(
void *c,
int name,
int val)
634 static int firstTime = 1;
654 cache_test_flush_fun,
NULL, cache_test_load_fun, &ctd);
658 cache_test_add(c, 1111, -11);
660 cache_test_add(c, 2222, -22);
662 cache_test_add(c, 3333, -33);
664 cache_test_add(c, 4444, -44);
670 cache_test_add(c, 5555, -55);
672 cache_test_add(c, 6666, -66);
674 cache_test_add(c, 7777, -77);
676 cache_test_add(c, 8888, -88);
678 cache_test_add(c, 9999, -99);
684 cache_test_add(c, 1111, -11);
686 cache_test_add(c, 2222, -22);
688 cache_test_add(c, 3333, -33);
692 cache_test_add(c, 1111, -11);
694 cache_test_add(c, 2222, -22);
696 cache_test_add(c, 3333, -33);
void Rast3d_cache_reset(RASTER3D_cache *c)
#define IS_NOT_IN_QUEUE_ELT(elt)
void Rast3d_cache_dispose(RASTER3D_cache *c)
int Rast3d_cache_remove_all(RASTER3D_cache *c)
void * Rast3d_malloc(int)
Same as malloc (nBytes), except that in case of error Rast3d_error() is invoked.
void * Rast3d_cache_hash_new(int)
void Rast3d_cache_set_remove_fun(RASTER3D_cache *c, int(*eltRemoveFun)(), void *eltRemoveFunData)
int Rast3d_cache_flush(RASTER3D_cache *c, int name)
int Rast3d_cache_load(RASTER3D_cache *c, int name)
void Rast3d_cache_set_load_fun(RASTER3D_cache *c, int(*eltLoadFun)(), void *eltLoadFunData)
#define IS_ACTIVE_ELT(elt)
void Rast3d_cache_hash_load_name(Rast3d_cache_hash *, int, int)
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
int Rast3d_cache_unlock(RASTER3D_cache *c, int name)
void Rast3d_cache_hash_reset(Rast3d_cache_hash *)
int Rast3d_cache_put_elt(RASTER3D_cache *c, int name, const void *src)
void Rast3d_error(const char *,...) __attribute__((format(printf
#define ONE_UNLOCKED_ELT_ONLY
void Rast3d_cache_hash_dispose(Rast3d_cache_hash *)
#define IS_NOT_ACTIVE_ELT(elt)
#define IS_LOCKED_ELT(elt)
int Rast3d_cache_lock_all(RASTER3D_cache *c)
void * Rast3d_cache_elt_ptr(RASTER3D_cache *c, int name)
void Rast3d_cache_autolock_on(RASTER3D_cache *c)
#define IS_IN_QUEUE_ELT(elt)
void Rast3d_cache_lock_intern(RASTER3D_cache *c, int index)
int Rast3d_cache_hash_name2index(Rast3d_cache_hash *, int)
void Rast3d_cache_set_min_unlock(RASTER3D_cache *c, int nofMinUnLocked)
int Rast3d_cache_get_elt(RASTER3D_cache *c, int name, void *dst)
#define DEACTIVATE_ELT(elt)
int Rast3d_cache_lock(RASTER3D_cache *c, int name)
int Rast3d_cache_unlock_all(RASTER3D_cache *c)
int read_fn(int, void *, void *)
void Rast3d_cache_autolock_off(RASTER3D_cache *c)
int Rast3d_cache_flush_all(RASTER3D_cache *c)
void * Rast3d_cache_new(int nofElts, int sizeOfElts, int nofNames, int(*eltRemoveFun)(), void *eltRemoveFunData, int(*eltLoadFun)(), void *eltLoadFunData)
void Rast3d_cache_hash_remove_name(Rast3d_cache_hash *, int)
#define IS_UNLOCKED_ELT(elt)
void * Rast3d_cache_new_read(int nofElts, int sizeOfElts, int nofNames, read_fn *eltLoadFun, void *eltLoadFunData)
int Rast3d_cache_remove_elt(RASTER3D_cache *c, int name)
void Rast3d_free(void *)
Same as free (ptr).