gc_disclaim.h 2.7 KB

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