| 1 |
/* |
| 2 |
* Copyright (c) 2007-2011 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 |
#ifndef GC_DISCLAIM_H |
| 16 |
#define GC_DISCLAIM_H |
| 17 |
|
| 18 |
#include "gc.h" |
| 19 |
|
| 20 |
#ifdef __cplusplus |
| 21 |
extern "C" { |
| 22 |
#endif |
| 23 |
|
| 24 |
/* This API is defined only if the library has been suitably compiled */ |
| 25 |
/* (i.e. with ENABLE_DISCLAIM defined). */ |
| 26 |
|
| 27 |
/* Prepare the object kind used by GC_finalized_malloc. Call it from */ |
| 28 |
/* your initialization code or, at least, at some point before using */ |
| 29 |
/* finalized allocations. The function is thread-safe. */ |
| 30 |
GC_API void GC_CALL GC_init_finalized_malloc(void); |
| 31 |
|
| 32 |
/* Type of a disclaim call-back. */ |
| 33 |
typedef int (GC_CALLBACK * GC_disclaim_proc)(void * /*obj*/); |
| 34 |
|
| 35 |
/* Register "proc" to be called on each object of "kind" ready to be */ |
| 36 |
/* reclaimed. If "proc" returns non-zero, the collector will not */ |
| 37 |
/* reclaim the object on this GC cycle. Objects reachable from "proc" */ |
| 38 |
/* will be protected from collection if "mark_from_all" is non-zero, */ |
| 39 |
/* but at the expense that long chains of objects will take many cycles */ |
| 40 |
/* to reclaim. */ |
| 41 |
GC_API void GC_CALL GC_register_disclaim_proc(int /*kind*/, |
| 42 |
GC_disclaim_proc /*proc*/, |
| 43 |
int /*mark_from_all*/); |
| 44 |
|
| 45 |
/* The finalizer closure used by GC_finalized_malloc. */ |
| 46 |
struct GC_finalizer_closure { |
| 47 |
GC_finalization_proc proc; |
| 48 |
void *cd; |
| 49 |
}; |
| 50 |
|
| 51 |
/* Allocate "size" bytes which is finalized by "fc". This uses a */ |
| 52 |
/* dedicated object kind with a disclaim procedure, and is more */ |
| 53 |
/* efficient than GC_register_finalizer and friends. */ |
| 54 |
/* GC_init_finalized_malloc must be called before using this. */ |
| 55 |
/* Note that GC_size (applied to such allocated object) returns a value */ |
| 56 |
/* slightly bigger than the specified allocation size, and that GC_base */ |
| 57 |
/* result points to a word prior to the start of the allocated object. */ |
| 58 |
GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void * GC_CALL |
| 59 |
GC_finalized_malloc(size_t /*size*/, |
| 60 |
const struct GC_finalizer_closure * /*fc*/); |
| 61 |
|
| 62 |
#ifdef __cplusplus |
| 63 |
} /* extern "C" */ |
| 64 |
#endif |
| 65 |
|
| 66 |
#endif |