gsgc.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Copyright (C) 1996, 1999, 2001 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gsgc.h,v 1.6 2002/06/16 08:45:42 lpd Exp $ */
  14. /* Library-level interface to garbage collector */
  15. /*
  16. * This API is not strictly at the library level, since it references
  17. * gs_ref_memory_t and the 4 PostScript memory spaces; however, the former
  18. * concept already leaks into the library's standard allocator, and the
  19. * latter is relatively small and harmless.
  20. */
  21. #ifndef gsgc_INCLUDED
  22. # define gsgc_INCLUDED
  23. /*
  24. * Define the VM space numbers, in increasing order of dynamism. Pointers
  25. * from a higher-numbered space to the same or a lower-numbered space are
  26. * always allowed, but not vice versa. Foreign space (the most static) is
  27. * internal, the rest are visible to the programmer; the index of foreign
  28. * space must be 0, so that we don't have to set any space bits in scalar
  29. * refs (PostScript objects).
  30. */
  31. typedef enum {
  32. i_vm_foreign = 0, /* must be 0 */
  33. i_vm_system,
  34. i_vm_global,
  35. i_vm_local,
  36. i_vm_max = i_vm_local
  37. } i_vm_space;
  38. /*
  39. * Define an array of allocators indexed by space. Note that the first
  40. * ("foreign") element of this array is always 0: foreign pointers, by
  41. * definition, point to objects that are not managed by a Ghostscript
  42. * allocator (typically, static const objects, or objects allocated with
  43. * malloc by some piece of code other than Ghostscript).
  44. */
  45. #ifndef gs_ref_memory_DEFINED
  46. # define gs_ref_memory_DEFINED
  47. typedef struct gs_ref_memory_s gs_ref_memory_t;
  48. #endif
  49. /*
  50. * r_space_bits is only defined in PostScript interpreters, but if it is
  51. * defined, we want to make sure it's 2.
  52. */
  53. #ifdef r_space_bits
  54. # if r_space_bits != 2
  55. Error_r_space_bits_is_not_2;
  56. # endif
  57. #endif
  58. typedef struct vm_spaces_s vm_spaces;
  59. /*
  60. * The garbage collection procedure is named vm_reclaim so as not to
  61. * collide with the reclaim member of gs_dual_memory_t.
  62. */
  63. #define vm_reclaim_proc(proc)\
  64. void proc(vm_spaces *pspaces, bool global)
  65. struct vm_spaces_s {
  66. vm_reclaim_proc((*vm_reclaim));
  67. union {
  68. gs_ref_memory_t *indexed[4 /*1 << r_space_bits */ ];
  69. struct _ssn {
  70. gs_ref_memory_t *foreign;
  71. gs_ref_memory_t *system;
  72. gs_ref_memory_t *global;
  73. gs_ref_memory_t *local;
  74. } named;
  75. } memories;
  76. };
  77. /*
  78. * By convention, the vm_spaces member of structures, and local variables
  79. * of type vm_spaces, are named spaces.
  80. */
  81. #define space_foreign spaces.memories.named.foreign
  82. #define space_system spaces.memories.named.system
  83. #define space_global spaces.memories.named.global
  84. #define space_local spaces.memories.named.local
  85. #define spaces_indexed spaces.memories.indexed
  86. /*
  87. * Define the top-level entry to the garbage collectors.
  88. */
  89. #define GS_RECLAIM(pspaces, global) ((pspaces)->vm_reclaim(pspaces, global))
  90. /* Backward compatibility */
  91. #define gs_reclaim(pspaces, global) GS_RECLAIM(pspaces, global)
  92. #endif /* gsgc_INCLUDED */