| 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. Called with the allocation lock held. */ |
| 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 ("proc" should not try to */ |
| 38 |
/* resurrect the object otherwise). Objects reachable from "proc" */ |
| 39 |
/* (including the referred closure object) will be protected from */ |
| 40 |
/* collection if "mark_from_all" is non-zero, but at the expense that */ |
| 41 |
/* long chains of objects will take many cycles to reclaim. */ |
| 42 |
/* Calls to GC_free() will free its argument without inquiring "proc". */ |
| 43 |
/* No-op in the leak-finding mode. */ |
| 44 |
GC_API void GC_CALL GC_register_disclaim_proc(int /*kind*/, |
| 45 |
GC_disclaim_proc /*proc*/, |
| 46 |
int /*mark_from_all*/); |
| 47 |
|
| 48 |
/* The finalizer closure used by GC_finalized_malloc. */ |
| 49 |
struct GC_finalizer_closure { |
| 50 |
GC_finalization_proc proc; |
| 51 |
void *cd; |
| 52 |
}; |
| 53 |
|
| 54 |
/* Allocate "size" bytes which is finalized by "fc". This uses a */ |
| 55 |
/* dedicated object kind with a disclaim procedure, and is more */ |
| 56 |
/* efficient than GC_register_finalizer and friends. */ |
| 57 |
/* GC_init_finalized_malloc must be called before using this. */ |
| 58 |
/* The collector will reclaim the object during this GC cycle (thus, */ |
| 59 |
/* "proc" should not try to resurrect the object). The other objects */ |
| 60 |
/* reachable from "proc" (including the closure object in case it is */ |
| 61 |
/* a heap-allocated one) will be protected from collection. */ |
| 62 |
/* Note that GC_size (applied to such allocated object) returns a value */ |
| 63 |
/* slightly bigger than the specified allocation size, and that GC_base */ |
| 64 |
/* result points to a word prior to the start of the allocated object. */ |
| 65 |
/* The disclaim procedure is not invoked in the leak-finding mode. */ |
| 66 |
/* There is no debugging version of this allocation API. */ |
| 67 |
GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void * GC_CALL |
| 68 |
GC_finalized_malloc(size_t /*size*/, |
| 69 |
const struct GC_finalizer_closure * /*fc*/) GC_ATTR_NONNULL(2); |
| 70 |
|
| 71 |
#ifdef __cplusplus |
| 72 |
} /* extern "C" */ |
| 73 |
#endif |
| 74 |
|
| 75 |
#endif |