1
/* Copyright (c) 2005 PrimeBase Technologies GmbH
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* 2005-01-10 Paul McCullagh
28
#include "memory_xt.h"
33
* Heap memory has a reference count, and a lock for shared access.
34
* It also has a finalize routine which is called before the memory is
37
typedef void (*XTFinalizeFunc)(struct XTThread *self, void *heap_ptr);
38
typedef void (*XTOnReleaseFunc)(void *heap_ptr);
40
typedef struct XTHeap {
41
XTSpinLockRec h_lock; /* Prevent concurrent access to the heap memory: */
42
u_int h_ref_count; /* So we know when to free (EVERY pointer reference MUST be counted). */
43
XTFinalizeFunc h_finalize; /* If non-NULL, call before freeing. */
44
XTOnReleaseFunc h_onrelease; /* If non-NULL, call on release. */
48
} XTHeapRec, *XTHeapPtr;
50
/* Returns with reference count = 1 */
51
XTHeapPtr xt_heap_new(struct XTThread *self, size_t size, XTFinalizeFunc finalize);
52
XTHeapPtr xt_mm_heap_new(struct XTThread *self, size_t size, XTFinalizeFunc finalize, u_int line, c_char *file, xtBool track);
54
void xt_heap_set_release_callback(XTHeapPtr mem, XTOnReleaseFunc onrelease);
56
void xt_heap_reference(struct XTThread *self, XTHeapPtr mem);
57
void xt_mm_heap_reference(struct XTThread *self, XTHeapPtr hp, u_int line, c_char *file);
59
void xt_heap_release(struct XTThread *self, XTHeapPtr mem);
60
void xt_heap_release_ns(XTHeapPtr mem);
61
u_int xt_heap_get_ref_count(struct XTThread *self, XTHeapPtr mem);
63
void xt_check_heap(struct XTThread *self, XTHeapPtr mem);
66
#define xt_heap_new(t, s, f) xt_mm_heap_new(t, s, f, __LINE__, __FILE__, FALSE)
67
#define xt_heap_new_track(t, s, f) xt_mm_heap_new(t, s, f, __LINE__, __FILE__, TRUE)
68
#define xt_heap_reference(t, s) xt_mm_heap_reference(t, s, __LINE__, __FILE__)
69
#define xt_heap_reference_ns(s) xt_mm_heap_reference(NULL, s, __LINE__, __FILE__)
71
#define xt_heap_reference_ns(s) xt_heap_reference(NULL, s)