GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cache.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <unistd.h>
6 #include <grass/G3d.h>
7 #include "G3d_intern.h"
8 #include "cachehash.h"
9 
10 /*---------------------------------------------------------------------------*/
11 
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))
18 
19 #define DEACTIVATE_ELT(elt) ((IS_LOCKED_ELT(elt) ? \
20  (c->nofUnlocked)++ : (0)), \
21  c->locks[elt] = 2)
22 #define LOCK_ELT(elt) ((IS_LOCKED_ELT(elt) ? \
23  (0) : (c->nofUnlocked)--), \
24  (c->locks[elt] = 1))
25 #define UNLOCK_ELT(elt) ((IS_LOCKED_ELT(elt) ? \
26  (c->nofUnlocked)++ : (0)), \
27  (c->locks[elt] = 0))
28 
29 #define ONE_UNLOCKED_ELT_ONLY (c->first == c->last)
30 #define ARE_MIN_UNLOCKED (c->nofUnlocked <= c->minUnlocked)
31 
32 /*---------------------------------------------------------------------------*/
33 
34 void G3d_cache_reset(G3D_cache * c)
35 {
36  int i;
37 
38  for (i = 0; i < c->nofElts; i++) {
39  DEACTIVATE_ELT(i);
40  c->next[i] = i + 1;
41  c->prev[i] = i - 1;
42  c->names[i] = -1;
43  }
44 
45  c->prev[0] = c->next[c->nofElts - 1] = -1;
46  c->first = 0;
47  c->last = c->nofElts - 1;
48 
49  c->autoLock = 0;
50  c->nofUnlocked = c->nofElts;
51  c->minUnlocked = 1;
52 
53  G3d_cache_hash_reset(c->hash);
54 }
55 
56 /*---------------------------------------------------------------------------*/
57 
58 static int cache_dummy_fun(int tileIndex, const void *tileBuf, void *map)
59 {
60  return 1;
61 }
62 
63 /*---------------------------------------------------------------------------*/
64 
65 void G3d_cache_dispose(G3D_cache * c)
66 {
67  if (c == NULL)
68  return;
69 
70  G3d_cache_hash_dispose(c->hash);
71 
72  if (c->elts != NULL)
73  G3d_free(c->elts);
74  if (c->names != NULL)
75  G3d_free(c->names);
76  if (c->locks != NULL)
77  G3d_free(c->locks);
78  if (c->next != NULL)
79  G3d_free(c->next);
80  if (c->prev != NULL)
81  G3d_free(c->prev);
82 
83  G3d_free(c);
84 }
85 
86 /*---------------------------------------------------------------------------*/
87 
88 void *G3d_cache_new(int nofElts, int sizeOfElts, int nofNames,
89  int (*eltRemoveFun) (), void *eltRemoveFunData,
90  int (*eltLoadFun) (), void *eltLoadFunData)
91 {
92  G3D_cache *tmp;
93  int i;
94 
95  tmp = G3d_malloc(sizeof(G3D_cache));
96  if (tmp == NULL) {
97  G3d_error("G3d_cache_new: error in G3d_malloc");
98  return (void *)NULL;
99  }
100 
101  tmp->hash = NULL;
102 
103  tmp->nofElts = nofElts;
104  tmp->eltSize = sizeOfElts;
105  tmp->elts = G3d_malloc(tmp->eltSize * tmp->nofElts);
106  tmp->names = G3d_malloc(sizeof(int) * tmp->nofElts);
107  tmp->locks = G3d_malloc(tmp->nofElts);
108  tmp->next = G3d_malloc(sizeof(int) * tmp->nofElts);
109  tmp->prev = G3d_malloc(sizeof(int) * tmp->nofElts);
110 
111  if ((tmp->elts == NULL) || (tmp->names == NULL) || (tmp->locks == NULL) ||
112  (tmp->next == NULL) || (tmp->prev == NULL)) {
113 
114  G3d_cache_dispose(tmp);
115  G3d_error("G3d_cache_new: error in G3d_malloc");
116  return (void *)NULL;
117  }
118 
119  /* Init the cache lock */
120  for(i = 0; i < tmp->nofElts; i++)
121  tmp->locks[i] = 0;
122 
123  tmp->eltRemoveFun = eltRemoveFun;
124  tmp->eltRemoveFunData = eltRemoveFunData;
125  tmp->eltLoadFun = eltLoadFun;
126  tmp->eltLoadFunData = eltLoadFunData;
127 
128  tmp->hash = G3d_cache_hash_new(nofNames);
129  if (tmp->hash == NULL) {
130  G3d_cache_dispose(tmp);
131  G3d_error("G3d_cache_new: error in G3d_cache_hash_new");
132  return (void *)NULL;
133  }
134 
135  G3d_cache_reset(tmp);
136 
137  return tmp;
138 }
139 
140 /*---------------------------------------------------------------------------*/
141 
142 void
143 G3d_cache_set_removeFun(G3D_cache * c, int (*eltRemoveFun) (),
144  void *eltRemoveFunData)
145 {
146  c->eltRemoveFun = eltRemoveFun;
147  c->eltRemoveFunData = eltRemoveFunData;
148 }
149 
150 /*---------------------------------------------------------------------------*/
151 
152 void
153 G3d_cache_set_loadFun(G3D_cache * c, int (*eltLoadFun) (),
154  void *eltLoadFunData)
155 {
156  c->eltLoadFun = eltLoadFun;
157  c->eltLoadFunData = eltLoadFunData;
158 }
159 
160 /*---------------------------------------------------------------------------*/
161 
162 void *G3d_cache_new_read(int nofElts, int sizeOfElts, int nofNames,
163  read_fn * eltLoadFun, void *eltLoadFunData)
164 {
165  return G3d_cache_new(nofElts, sizeOfElts, nofNames,
166  cache_dummy_fun, NULL, eltLoadFun, eltLoadFunData);
167 }
168 
169 /*---------------------------------------------------------------------------*/
170 
171 static void cache_queue_dequeue(G3D_cache * c, int index)
172 {
173  if (IS_NOT_IN_QUEUE_ELT(index))
174  G3d_fatalError("cache_queue_dequeue: index not in queue");
175 
176  if (index == c->first)
177  c->first = c->next[index];
178  if (index == c->last)
179  c->last = c->prev[index];
180 
181  if (c->next[index] != -1)
182  c->prev[c->next[index]] = c->prev[index];
183  if (c->prev[index] != -1)
184  c->next[c->prev[index]] = c->next[index];
185 
186  c->next[index] = c->prev[index] = -1;
187 }
188 
189 /*---------------------------------------------------------------------------*/
190 
191 static void cache_queue_enqueue(G3D_cache * c, int left, int index)
192 {
193  if (IS_IN_QUEUE_ELT(index))
194  G3d_fatalError("cache_queue_enqueue: index already in queue");
195 
196  if (c->first == -1) {
197  if (left != c->last)
198  G3d_fatalError("cache_queue_enqueue: position out of range");
199 
200  c->first = c->last = index;
201  return;
202  }
203 
204  if (left >= 0 && IS_NOT_IN_QUEUE_ELT(left))
205  G3d_fatalError("cache_queue_enqueue: position not in queue");
206 
207 
208  if (left == -1) {
209  c->next[index] = c->first;
210  c->prev[c->first] = index;
211  c->first = index;
212 
213  return;
214  }
215 
216  c->prev[index] = left;
217 
218  if (c->next[left] == -1) {
219  c->next[left] = index;
220  c->last = index;
221 
222  return;
223  }
224 
225  c->prev[c->next[left]] = index;
226  c->next[index] = c->next[left];
227  c->next[left] = index;
228 }
229 
230 /*---------------------------------------------------------------------------*/
231 
232 static int cache_queue_get_top(G3D_cache * c)
233 {
234  int top;
235 
236  top = c->first;
237 
238  cache_queue_dequeue(c, c->first);
239 
240  return top;
241 }
242 
243 /*---------------------------------------------------------------------------*/
244 
245 static void cache_queue_append(G3D_cache * c, int index)
246 {
247  cache_queue_enqueue(c, c->last, index);
248 }
249 
250 /*---------------------------------------------------------------------------*/
251 
252 static void cache_queue_preppend(G3D_cache * c, int index)
253 {
254  cache_queue_enqueue(c, -1, index);
255 }
256 
257 /*---------------------------------------------------------------------------*/
258 
259 /*---------------------------------------------------------------------------*/
260 
261  /* EXPORTED FUNCTIONS */
262 
263 /*---------------------------------------------------------------------------*/
264 
265 /*---------------------------------------------------------------------------*/
266 
267 int G3d_cache_lock(G3D_cache * c, int name)
268 {
269  int index;
270 
271  index = G3d_cache_hash_name2index(c->hash, name);
272  if (index == -1) {
273  G3d_error("G3d_cache_lock: name not in cache");
274  return 0;
275  }
276 
277  if (IS_LOCKED_ELT(index))
278  return 1;
280  return -1;
281  if (ARE_MIN_UNLOCKED)
282  return -1;
283 
284  cache_queue_dequeue(c, index);
285  LOCK_ELT(index);
286 
287  return 1;
288 }
289 
290 /*---------------------------------------------------------------------------*/
291 
292 void G3d_cache_lock_intern(G3D_cache * c, int index)
293 {
294  if (IS_LOCKED_ELT(index))
295  return;
296 
297  cache_queue_dequeue(c, index);
298  LOCK_ELT(index);
299 }
300 
301 /*---------------------------------------------------------------------------*/
302 
303 int G3d_cache_unlock(G3D_cache * c, int name)
304 {
305  int index;
306 
307  index = G3d_cache_hash_name2index(c->hash, name);
308  if (index == -1) {
309  G3d_error("G3d_cache_unlock: name not in cache");
310  return 0;
311  }
312 
313  if (IS_UNLOCKED_ELT(index))
314  return 1;
315 
316  cache_queue_append(c, index);
317  UNLOCK_ELT(index);
318 
319  return 1;
320 }
321 
322 /*---------------------------------------------------------------------------*/
323 
324 int G3d_cache_unlock_all(G3D_cache * c)
325 {
326  int index;
327 
328  for (index = 0; index < c->nofElts; index++)
329  if (IS_LOCKED_ELT(index))
330  if (!G3d_cache_unlock(c, c->names[index])) {
331  G3d_error("G3d_cache_unlock_all: error in G3d_cache_unlock");
332  return 0;
333  }
334 
335  return 1;
336 }
337 
338 /*---------------------------------------------------------------------------*/
339 
340 int G3d_cache_lock_all(G3D_cache * c)
341 {
342  int index;
343 
344  for (index = 0; index < c->nofElts; index++)
345  if (IS_UNLOCKED_ELT(index))
346  G3d_cache_lock_intern(c, index);
347 
348  return 1;
349 }
350 
351 /*---------------------------------------------------------------------------*/
352 
353 void G3d_cache_autolock_on(G3D_cache * c)
354 {
355  c->autoLock = 1;
356 }
357 
358 /*---------------------------------------------------------------------------*/
359 
360 void G3d_cache_autolock_off(G3D_cache * c)
361 {
362  c->autoLock = 0;
363 }
364 
365 /*---------------------------------------------------------------------------*/
366 
367 void G3d_cache_set_minUnlock(G3D_cache * c, int nofMinUnLocked)
368 {
369  c->minUnlocked = nofMinUnLocked;
370 }
371 
372 /*---------------------------------------------------------------------------*/
373 
374 static int cache_remove_elt(G3D_cache * c, int name, int doFlush)
375 {
376  int index;
377 
378  index = G3d_cache_hash_name2index(c->hash, name);
379  if (index == -1) {
380  G3d_error("G3d_cache_deactivate_elt : name not in cache");
381  return 0;
382  }
383 
384  if (IS_NOT_ACTIVE_ELT(index))
385  return 1;
386 
387  if (IS_IN_QUEUE_ELT(index)) {
388  cache_queue_dequeue(c, index);
389  LOCK_ELT(index);
390  }
391 
392  if (doFlush)
393  if (!c->eltRemoveFun(name, c->elts + c->eltSize * index,
394  c->eltRemoveFunData)) {
395  G3d_error("cache_remove_elt: error in c->eltRemoveFun");
396  return 0;
397  }
398 
399  cache_queue_preppend(c, index);
400  DEACTIVATE_ELT(index);
401 
402  G3d_cache_hash_remove_name(c->hash, name);
403 
404  return 1;
405 }
406 
407 /*---------------------------------------------------------------------------*/
408 
409 int G3d_cache_remove_elt(G3D_cache * c, int name)
410 {
411  if (!cache_remove_elt(c, name, 0)) {
412  G3d_error("G3d_cache_remove_elt: error in cache_remove_elt");
413  return 0;
414  }
415 
416  return 1;
417 }
418 
419 /*---------------------------------------------------------------------------*/
420 
421 int G3d_cache_flush(G3D_cache * c, int name)
422 {
423  if (!cache_remove_elt(c, name, 1)) {
424  G3d_error("G3d_cache_flush: error in cache_remove_elt");
425  return 0;
426  }
427 
428  return 1;
429 }
430 
431 /*---------------------------------------------------------------------------*/
432 
433 int G3d_cache_remove_all(G3D_cache * c)
434 {
435  int index;
436 
437  for (index = 0; index < c->nofElts; index++)
438  if (IS_ACTIVE_ELT(index))
439  if (!G3d_cache_remove_elt(c, c->names[index])) {
440  G3d_error
441  ("G3d_cache_remove_all: error in G3d_cache_remove_elt");
442  return 0;
443  }
444 
445  return 1;
446 }
447 
448 /*---------------------------------------------------------------------------*/
449 
450 int G3d_cache_flush_all(G3D_cache * c)
451 {
452  int index;
453 
454  for (index = 0; index < c->nofElts; index++)
455  if (IS_ACTIVE_ELT(index))
456  if (!G3d_cache_flush(c, c->names[index])) {
457  G3d_error("G3d_cache_flush_all: error in G3d_cache_flush");
458  return 0;
459  }
460 
461  return 1;
462 }
463 
464 /*---------------------------------------------------------------------------*/
465 
466 void *G3d_cache_elt_ptr(G3D_cache * c, int name)
467 {
468  int index, oldName, doUnlock;
469 
470  index = G3d_cache_hash_name2index(c->hash, name);
471 
472  if (index != -1) {
473  if (c->autoLock)
474  if (IS_UNLOCKED_ELT(index) && (!ONE_UNLOCKED_ELT_ONLY) &&
475  (!ARE_MIN_UNLOCKED))
476  G3d_cache_lock_intern(c, index);
477 
478  return c->elts + c->eltSize * index;
479  }
480 
481  index = c->first;
482  if (IS_ACTIVE_ELT(index)) {
483  oldName = c->names[index];
484  G3d_cache_hash_remove_name(c->hash, oldName);
485  if (!c->eltRemoveFun(oldName, c->elts + c->eltSize * index,
486  c->eltRemoveFunData)) {
487  G3d_error("G3d_cache_elt_ptr: error in c->eltRemoveFun");
488  return NULL;
489  }
490  }
491 
492  G3d_cache_hash_load_name(c->hash, name, index);
493 
494  doUnlock = ((!c->autoLock) || ONE_UNLOCKED_ELT_ONLY || ARE_MIN_UNLOCKED);
495 
496  UNLOCK_ELT(index);
497  c->names[index] = name;
498  G3d_cache_lock_intern(c, index);
499 
500  if (doUnlock)
501  if (!G3d_cache_unlock(c, name)) {
502  G3d_error("G3d_cache_elt_ptr: error in G3d_cache_unlock");
503  return NULL;
504  }
505 
506  if (!c->eltLoadFun(name, c->elts + c->eltSize * index, c->eltLoadFunData)) {
507  G3d_error("G3d_cache_elt_ptr: error in c->eltLoadFun");
508  return NULL;
509  }
510 
511  return c->elts + c->eltSize * index;
512 }
513 
514 /*---------------------------------------------------------------------------*/
515 
516 int G3d_cache_load(G3D_cache * c, int name)
517 {
518  if (G3d_cache_elt_ptr(c, name) == NULL) {
519  G3d_error("G3d_cache_load: error in G3d_cache_elt_ptr");
520  return 0;
521  }
522 
523  return 1;
524 }
525 
526 /*---------------------------------------------------------------------------*/
527 
528 int G3d_cache_get_elt(G3D_cache * c, int name, void *dst)
529 {
530  const void *elt;
531 
532  elt = G3d_cache_elt_ptr(c, name);
533  if (elt == NULL) {
534  G3d_error("G3d_cache_get_elt: error in G3d_cache_elt_ptr");
535  return 0;
536  }
537 
538  memcpy(dst, elt, c->eltSize);
539 
540  return 1;
541 }
542 
543 /*---------------------------------------------------------------------------*/
544 
545 int G3d_cache_put_elt(G3D_cache * c, int name, const void *src)
546 {
547  void *elt;
548 
549  elt = G3d_cache_elt_ptr(c, name);
550  if (elt == NULL) {
551  G3d_error("G3d_cache_put_elt: error in G3d_cache_elt_ptr");
552  return 0;
553  }
554 
555  memcpy(elt, src, c->eltSize);
556 
557  return 1;
558 }
559 
560 /*---------------------------------------------------------------------------*/
561 
562 /*---------------------------------------------------------------------------*/
563 
564  /* TEST FUNCTIONS */
565 
566 /*---------------------------------------------------------------------------*/
567 
568 /*---------------------------------------------------------------------------*/
569 
570 static void cache_test_print(G3D_cache * c)
571 {
572  int i, al;
573  int *a;
574 
575  al = c->autoLock;
577 
578  printf("\n--------------------------------\n");
579  for (i = 0; i < c->nofElts; i++) {
580  printf("elt %d: ", i);
581  if (IS_NOT_ACTIVE_ELT(i)) {
582  printf("na\n");
583  continue;
584  }
585 
586  a = (int *)G3d_cache_elt_ptr(c, c->names[i]);
587  /*G3d_cache_get_elt (c, c->names[i], a); */
588  printf("name %d val %d %s\n", c->names[i], a[17],
589  (IS_LOCKED_ELT(i) ? "locked" :
590  IS_UNLOCKED_ELT(i) ? "unlocked" : ""));
591  }
592  printf("\n--------------------------------\n");
593 
594  if (al)
596 }
597 
598 /*---------------------------------------------------------------------------*/
599 
600 static int cache_test_flush_fun(int name, const void *eltPtr, void *data)
601 {
602  printf("flushing name %d value %d\n", name, ((const int *)eltPtr)[17]);
603  return 0;
604 }
605 
606 /*---------------------------------------------------------------------------*/
607 
608 typedef struct
609 {
610 
611  int *value;
612  int size;
613 
615 
616 static int cache_test_load_fun(int name, void *eltPtr, void *data)
617 {
618  const void *src;
619 
620  printf("loading name %d value %d\n", name,
621  ((cache_test_data_type *) data)->value[17]);
622 
623  src = ((cache_test_data_type *) data)->value;
624  memcpy(eltPtr, src, ((cache_test_data_type *) data)->size);
625 
626  return 0;
627 }
628 
629 /*---------------------------------------------------------------------------*/
630 
631 static cache_test_data_type ctd;
632 
633 static void cache_test_add(void *c, int name, int val)
634 {
635  static int firstTime = 1;
636 
637  if (firstTime) {
638  ctd.value = G3d_malloc(((G3D_cache *) c)->eltSize * sizeof(int));
639  firstTime = 0;
640  }
641 
642  ctd.value[17] = val;
643  ctd.size = ((G3D_cache *) c)->eltSize;
644 
645  G3d_cache_load(c, name);
646 }
647 
648 /*---------------------------------------------------------------------------*/
649 
650 int MAIN()
651 {
652  void *c;
653 
654  c = G3d_cache_new(3, 76 * sizeof(int), 100000,
655  cache_test_flush_fun, NULL, cache_test_load_fun, &ctd);
656 
658  cache_test_print(c);
659  cache_test_add(c, 1111, -11);
660  cache_test_print(c);
661  cache_test_add(c, 2222, -22);
662  cache_test_print(c);
663  cache_test_add(c, 3333, -33);
664  cache_test_print(c);
665  cache_test_add(c, 4444, -44);
666  cache_test_print(c);
668  cache_test_print(c);
669  G3d_cache_load(c, 2222);
670  cache_test_print(c);
671  cache_test_add(c, 5555, -55);
672  cache_test_print(c);
673  cache_test_add(c, 6666, -66);
674  cache_test_print(c);
675  cache_test_add(c, 7777, -77);
676  cache_test_print(c);
677  cache_test_add(c, 8888, -88);
678  cache_test_print(c);
679  cache_test_add(c, 9999, -99);
680  cache_test_print(c);
681  G3d_cache_flush(c, 9999);
682  cache_test_print(c);
684  cache_test_print(c);
685  cache_test_add(c, 1111, -11);
686  cache_test_print(c);
687  cache_test_add(c, 2222, -22);
688  cache_test_print(c);
689  cache_test_add(c, 3333, -33);
690  cache_test_print(c);
691  G3d_cache_reset(c);
692  cache_test_print(c);
693  cache_test_add(c, 1111, -11);
694  cache_test_print(c);
695  cache_test_add(c, 2222, -22);
696  cache_test_print(c);
697  cache_test_add(c, 3333, -33);
698  cache_test_print(c);
699 
700  return 0;
701 }
int MAIN()
Definition: cache.c:650
void * G3d_cache_new(int nofElts, int sizeOfElts, int nofNames, int(*eltRemoveFun)(), void *eltRemoveFunData, int(*eltLoadFun)(), void *eltLoadFunData)
Definition: cache.c:88
#define IS_NOT_IN_QUEUE_ELT(elt)
Definition: cache.c:16
int G3d_cache_remove_all(G3D_cache *c)
Definition: cache.c:433
void G3d_cache_lock_intern(G3D_cache *c, int index)
Definition: cache.c:292
#define ARE_MIN_UNLOCKED
Definition: cache.c:30
void G3d_free(void *buf)
Same as free (ptr).
Definition: g3dalloc.c:71
#define IS_NOT_ACTIVE_ELT(elt)
Definition: cache.c:13
void G3d_error(const char *msg,...)
Definition: g3derror.c:75
#define IS_ACTIVE_ELT(elt)
Definition: cache.c:12
string name
Definition: render.py:1314
void G3d_cache_set_loadFun(G3D_cache *c, int(*eltLoadFun)(), void *eltLoadFunData)
Definition: cache.c:153
int G3d_cache_unlock(G3D_cache *c, int name)
Definition: cache.c:303
int G3d_cache_load(G3D_cache *c, int name)
Definition: cache.c:516
#define IS_IN_QUEUE_ELT(elt)
Definition: cache.c:17
int G3d_cache_get_elt(G3D_cache *c, int name, void *dst)
Definition: cache.c:528
#define DEACTIVATE_ELT(elt)
Definition: cache.c:19
void G3d_cache_autolock_off(G3D_cache *c)
Definition: cache.c:360
void G3d_cache_set_minUnlock(G3D_cache *c, int nofMinUnLocked)
Definition: cache.c:367
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
void G3d_cache_hash_reset(G3d_cache_hash *h)
Definition: cachehash.c:25
int G3d_cache_put_elt(G3D_cache *c, int name, const void *src)
Definition: cache.c:545
void G3d_cache_autolock_on(G3D_cache *c)
Definition: cache.c:353
tuple data
void G3d_cache_hash_dispose(G3d_cache_hash *h)
Definition: cachehash.c:37
#define ONE_UNLOCKED_ELT_ONLY
Definition: cache.c:29
#define IS_LOCKED_ELT(elt)
Definition: cache.c:14
void * G3d_cache_hash_new(int nofNames)
Definition: cachehash.c:51
void G3d_cache_reset(G3D_cache *c)
Definition: cache.c:34
char * value
Definition: env.c:30
int G3d_cache_lock(G3D_cache *c, int name)
Definition: cache.c:267
int G3d_cache_flush(G3D_cache *c, int name)
Definition: cache.c:421
int G3d_cache_unlock_all(G3D_cache *c)
Definition: cache.c:324
void G3d_cache_dispose(G3D_cache *c)
Definition: cache.c:65
#define IS_UNLOCKED_ELT(elt)
Definition: cache.c:15
int G3d_cache_flush_all(G3D_cache *c)
Definition: cache.c:450
return NULL
Definition: dbfopen.c:1394
#define UNLOCK_ELT(elt)
Definition: cache.c:25
void * G3d_malloc(int nBytes)
Same as malloc (nBytes), except that in case of error G3d_error() is invoked.
Definition: g3dalloc.c:24
void * G3d_cache_new_read(int nofElts, int sizeOfElts, int nofNames, read_fn *eltLoadFun, void *eltLoadFunData)
Definition: cache.c:162
void G3d_cache_hash_load_name(G3d_cache_hash *h, int name, int index)
Definition: cachehash.c:92
int G3d_cache_lock_all(G3D_cache *c)
Definition: cache.c:340
void G3d_cache_hash_remove_name(G3d_cache_hash *h, int name)
Definition: cachehash.c:77
void * G3d_cache_elt_ptr(G3D_cache *c, int name)
Definition: cache.c:466
void G3d_cache_set_removeFun(G3D_cache *c, int(*eltRemoveFun)(), void *eltRemoveFunData)
Definition: cache.c:143
int G3d_cache_remove_elt(G3D_cache *c, int name)
Definition: cache.c:409
#define LOCK_ELT(elt)
Definition: cache.c:22
void G3d_fatalError(const char *,...)
This function prints the error message msg, and terminates the program with an error status...
Definition: g3derror.c:58
int G3d_cache_hash_name2index(G3d_cache_hash *h, int name)
Definition: cachehash.c:106