afsmonitor: avoid double free on exit
[openafs.git] / src / mcas / osi_mcas_obj_cache.c
1 #include "osi_mcas_obj_cache.h"
2 #include <osi/osi_includes.h>
3 #include <osi/osi_types.h>
4 #include <afs/afsutil.h>
5
6 void
7 osi_mcas_obj_cache_create(osi_mcas_obj_cache_t * gc_id, size_t size,
8         char *tag)
9 {
10     ViceLog(7,
11             ("osi_mcas_obj_cache_create: size, adjsize %d\n", size,
12              size + sizeof(int *)));
13
14     *(int *)gc_id = gc_add_allocator(size + sizeof(int *), tag);
15 }
16
17 void gc_trace(int alloc_id);
18 int gc_get_tag(int alloc_id);
19 int gc_get_blocksize(int alloc_id);
20
21 void *
22 osi_mcas_obj_cache_alloc(osi_mcas_obj_cache_t gc_id)
23 {
24     ptst_t *ptst;
25     void *obj;
26
27     ptst = critical_enter();
28     obj = (void *)gc_alloc(ptst, gc_id);
29     critical_exit(ptst);
30
31     ViceLog(11,
32                         ("GC: osi_mcas_obj_cache_alloc: block of size %d "
33 #if OSI_DATAMODEL_IS(OSI_ILP32_ENV)
34                          "0x%lx"
35 #else
36                          "0x%llx"
37 #endif
38                          " (%s)\n",
39                          gc_get_blocksize(gc_id),
40                          obj,
41                          gc_get_tag(gc_id)));
42
43     return (obj);
44 }
45
46 void
47 osi_mcas_obj_cache_free(osi_mcas_obj_cache_t gc_id, void *obj)
48 {
49     ptst_t *ptst;
50
51     ViceLog(11,
52                         ("GC: osi_mcas_obj_cache_free: block of size %d "
53 #if OSI_DATAMODEL_IS(OSI_ILP32_ENV)
54                          "0x%lx"
55 #else
56                          "0x%llx"
57 #endif
58                          " (%s)\n",
59                          gc_get_blocksize(gc_id),
60                          obj,
61                          gc_get_tag(gc_id)));
62
63     ptst = critical_enter();
64     gc_free(ptst, (void *)obj, gc_id);
65     critical_exit(ptst);
66 }
67
68 void
69 osi_mcas_obj_cache_destroy(osi_mcas_obj_cache_t gc_id)
70 {
71     /* TODO:  implement, will need to implement gc_remove_allocator and related
72      * modifications in gc.c */
73     return;
74 }