Add tracing to MCAS allocator and GC
[openafs.git] / src / mcas / gc.h
1 /*
2 Copyright (c) 2003, Keir Fraser All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7
8     * Redistributions of source code must retain the above copyright
9     * notice, this list of conditions and the following disclaimer.
10     * Redistributions in binary form must reproduce the above
11     * copyright notice, this list of conditions and the following
12     * disclaimer in the documentation and/or other materials provided
13     * with the distribution.  Neither the name of the Keir Fraser
14     * nor the names of its contributors may be used to endorse or
15     * promote products derived from this software without specific
16     * prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef __GC_H__
32 #define __GC_H__
33
34 typedef struct gc_st gc_t;
35
36 /* Most of these functions peek into a per-thread state struct. */
37 #include "ptst.h"
38
39 /* Initialise GC section of given per-thread state structure. */
40 gc_t *gc_init(void);
41
42 int gc_add_allocator(int alloc_size, char *tag);
43 void gc_remove_allocator(int alloc_id);
44
45 /*
46  * Memory allocate/free. An unsafe free can be used when an object was
47  * not made visible to other processes.
48  */
49 void *gc_alloc(ptst_t *ptst, int alloc_id);
50 void gc_free(ptst_t *ptst, void *p, int alloc_id);
51 void gc_unsafe_free(ptst_t *ptst, void *p, int alloc_id);
52
53 /*
54  * Hook registry. Allows users to hook in their own per-epoch delay
55  * lists.
56  */
57 typedef void (*hook_fn_t)(ptst_t *, void *);
58 int gc_add_hook(hook_fn_t fn);
59 void gc_remove_hook(int hook_id);
60 void gc_add_ptr_to_hook_list(ptst_t *ptst, void *ptr, int hook_id);
61
62 /* Per-thread entry/exit from critical regions */
63 void gc_enter(ptst_t *ptst);
64 void gc_exit(ptst_t *ptst);
65
66 /* Start-of-day initialisation of garbage collector. */
67 void _init_gc_subsystem(void);
68 void _destroy_gc_subsystem(void);
69
70 #endif /* __GC_H__ */