OSDN Git Service

2006-06-07 Petr Salinger <Petr.Salinger@seznam.cz>
[pf3gnuchains/gcc-fork.git] / boehm-gc / include / gc_local_alloc.h
1 /* 
2  * Copyright (c) 2000 by Hewlett-Packard Company.  All rights reserved.
3  *
4  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
6  *
7  * Permission is hereby granted to use or copy this program
8  * for any purpose,  provided the above notices are retained on all copies.
9  * Permission to modify the code and to distribute modified code is granted,
10  * provided the above notices are retained, and a notice that the code was
11  * modified is included with the above copyright notice.
12  */
13
14 /*
15  * Interface for thread local allocation.  Memory obtained
16  * this way can be used by all threads, as though it were obtained
17  * from an allocator like GC_malloc.  The difference is that GC_local_malloc
18  * counts the number of allocations of a given size from the current thread,
19  * and uses GC_malloc_many to perform the allocations once a threashold
20  * is exceeded.  Thus far less synchronization may be needed.
21  * Allocation of known large objects should not use this interface.
22  * This interface is designed primarily for fast allocation of small
23  * objects on multiprocessors, e.g. for a JVM running on an MP server.
24  *
25  * If this file is included with GC_GCJ_SUPPORT defined, GCJ-style
26  * bitmap allocation primitives will also be included.
27  *
28  * If this file is included with GC_REDIRECT_TO_LOCAL defined, then
29  * GC_MALLOC, GC_MALLOC_ATOMIC, and possibly GC_GCJ_MALLOC will
30  * be redefined to use the thread local allocatoor.
31  *
32  * The interface is available only if the collector is built with
33  * -DTHREAD_LOCAL_ALLOC, which is currently supported only on Linux.
34  *
35  * The debugging allocators use standard, not thread-local allocation.
36  *
37  * These routines normally require an explicit call to GC_init(), though
38  * that may be done from a constructor function.
39  */
40
41 #ifndef GC_LOCAL_ALLOC_H
42 #define GC_LOCAL_ALLOC_H
43
44 #ifndef _GC_H
45 #   include "gc.h"
46 #endif
47
48 #if defined(GC_GCJ_SUPPORT) && !defined(GC_GCJ_H)
49 #   include "gc_gcj.h"
50 #endif
51
52 /* We assume ANSI C for this interface. */
53
54 GC_PTR GC_local_malloc(size_t bytes);
55
56 GC_PTR GC_local_malloc_atomic(size_t bytes);
57
58 #if defined(GC_GCJ_SUPPORT)
59   GC_PTR GC_local_gcj_malloc(size_t bytes,
60                              void * ptr_to_struct_containing_descr);
61 #endif
62
63 # ifdef GC_DEBUG
64     /* We don't really use local allocation in this case.       */
65 #   define GC_LOCAL_MALLOC(s) GC_debug_malloc(s,GC_EXTRAS)
66 #   define GC_LOCAL_MALLOC_ATOMIC(s) GC_debug_malloc_atomic(s,GC_EXTRAS)
67 #   ifdef GC_GCJ_SUPPORT
68 #       define GC_LOCAL_GCJ_MALLOC(s,d) GC_debug_gcj_malloc(s,d,GC_EXTRAS)
69 #   endif
70 # else
71 #   define GC_LOCAL_MALLOC(s) GC_local_malloc(s)
72 #   define GC_LOCAL_MALLOC_ATOMIC(s) GC_local_malloc_atomic(s)
73 #   ifdef GC_GCJ_SUPPORT
74 #       define GC_LOCAL_GCJ_MALLOC(s,d) GC_local_gcj_malloc(s,d)
75 #   endif
76 # endif
77
78 # ifdef GC_REDIRECT_TO_LOCAL
79 #   undef GC_MALLOC
80 #   define GC_MALLOC(s) GC_LOCAL_MALLOC(s)
81 #   undef GC_MALLOC_ATOMIC
82 #   define GC_MALLOC_ATOMIC(s) GC_LOCAL_MALLOC_ATOMIC(s)
83 #   ifdef GC_GCJ_SUPPORT
84 #       undef GC_GCJ_MALLOC
85 #       define GC_GCJ_MALLOC(s,d) GC_LOCAL_GCJ_MALLOC(s,d)
86 #   endif
87 # endif
88
89 #endif /* GC_LOCAL_ALLOC_H */