~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/heap_xt.h

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2005 PrimeBase Technologies GmbH
 
2
 *
 
3
 * PrimeBase XT
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 *
 
19
 * 2005-01-10   Paul McCullagh
 
20
 *
 
21
 * H&G2JCtL
 
22
 */
 
23
#ifndef __xt_heap_h__
 
24
#define __xt_heap_h__
 
25
 
 
26
#include "xt_defs.h"
 
27
#include "lock_xt.h"
 
28
#include "memory_xt.h"
 
29
 
 
30
struct XTThread;
 
31
 
 
32
/*
 
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
 
35
 * freed.
 
36
 */
 
37
typedef void (*XTFinalizeFunc)(struct XTThread *self, void *heap_ptr);
 
38
typedef void (*XTOnReleaseFunc)(void *heap_ptr);
 
39
 
 
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. */
 
45
#ifdef DEBUG
 
46
        xtBool                                  h_track;
 
47
#endif
 
48
} XTHeapRec, *XTHeapPtr;
 
49
 
 
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);
 
53
 
 
54
void            xt_heap_set_release_callback(XTHeapPtr mem, XTOnReleaseFunc onrelease);
 
55
 
 
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);
 
58
 
 
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);
 
62
 
 
63
void            xt_check_heap(struct XTThread *self, XTHeapPtr mem);
 
64
 
 
65
#ifdef DEBUG_MEMORY
 
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__)
 
70
#else
 
71
#define xt_heap_reference_ns(s)         xt_heap_reference(NULL, s)
 
72
#endif
 
73
 
 
74
#endif