summaryrefslogtreecommitdiff
path: root/hieroglyph/hgallocator.h
blob: 118163bc04a2ab010c749f2921d526cc68943be2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * hgallocator.h
 * Copyright (C) 2006-2011 Akira TAGOH
 * 
 * Authors:
 *   Akira TAGOH  <akira@tagoh.org>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#if !defined (__HG_H_INSIDE__) && !defined (HG_COMPILATION)
#error "Only <hieroglyph/hg.h> can be included directly."
#endif

#ifndef __HIEROGLYPH_HGALLOCATOR_H__
#define __HIEROGLYPH_HGALLOCATOR_H__

#include <hieroglyph/hgtypes.h>
#include <hieroglyph/hgerror.h>
/* XXX: GLib is still needed to satisfy the GHashTable dependency */
#include <glib.h>

HG_BEGIN_DECLS

typedef struct _hg_allocator_data_t		hg_allocator_data_t;
typedef struct _hg_allocator_snapshot_data_t	hg_allocator_snapshot_data_t;
typedef struct _hg_mem_vtable_t			hg_mem_vtable_t;
typedef enum _hg_mem_flags_t			hg_mem_flags_t;

/**
 * hg_allocator_data_t:
 * @total_size:
 * @used_size:
 * @resizable:
 *
 * FIXME
 */
struct _hg_allocator_data_t {
	hg_usize_t total_size;
	hg_usize_t used_size;
	hg_bool_t  resizable;
};
/**
 * hg_allocator_snapshot_data_t:
 * @total_size:
 * @used_size:
 *
 * FIXME
 */
struct _hg_allocator_snapshot_data_t {
	hg_usize_t total_size;
	hg_usize_t used_size;
};
/**
 * hg_mem_flags_t:
 * @HG_MEM_RESTORABLE:
 *
 * FIXME
 */
enum _hg_mem_flags_t {
	HG_MEM_RESTORABLE      = 1 << 0,
};
/**
 * hg_mem_vtable_t:
 * @initialize:
 * @finalize:
 * @expand_heap:
 * @get_max_heap_size:
 * @alloc:
 * @realloc:
 * @free:
 * @lock_object:
 * @unlock_object:
 * @gc_init:
 * @gc_mark:
 * @gc_finish:
 * @save_snapshot:
 * @restore_snapshot:
 * @destroy_snapshot:
 *
 * FIXME
 */
struct _hg_mem_vtable_t {
	hg_pointer_t                   (* initialize)        (void);
	void                           (* finalize)          (hg_allocator_data_t           *data);
	hg_bool_t                      (* expand_heap)       (hg_allocator_data_t           *data,
							      hg_usize_t                     size);
	hg_usize_t                     (* get_max_heap_size) (hg_allocator_data_t           *data);
	hg_quark_t                     (* alloc)             (hg_allocator_data_t           *data,
							      hg_usize_t                     size,
							      hg_uint_t                      flags,
							      hg_pointer_t                  *ret);
	hg_quark_t                     (* realloc)           (hg_allocator_data_t           *data,
							      hg_quark_t                     quark,
							      hg_usize_t                     size,
							      hg_pointer_t                  *ret);
	void                           (* free)              (hg_allocator_data_t           *data,
							      hg_quark_t                     quark);
	hg_pointer_t                   (* lock_object)       (hg_allocator_data_t           *data,
							      hg_quark_t                     quark);
	void                           (* unlock_object)     (hg_allocator_data_t           *data,
							      hg_quark_t                     quark);
	hg_bool_t                      (* gc_init)           (hg_allocator_data_t           *data);
	hg_error_t                     (* gc_mark)           (hg_allocator_data_t           *data,
							      hg_quark_t                     quark);
	hg_error_t                     (* gc_finish)         (hg_allocator_data_t           *data,
							      hg_error_t                     error);
	hg_allocator_snapshot_data_t * (* save_snapshot)     (hg_allocator_data_t           *data);
	hg_bool_t                      (* restore_snapshot)  (hg_allocator_data_t           *data,
							      hg_allocator_snapshot_data_t  *snapshot,
							      GHashTable                    *references);
	void                           (* destroy_snapshot)  (hg_allocator_data_t           *data,
							      hg_allocator_snapshot_data_t  *snapshot);
};


hg_mem_vtable_t *hg_allocator_get_vtable   (void) G_GNUC_CONST;

HG_END_DECLS

#endif /* __HIEROGLYPH_HGALLOCATOR_H__ */