zend_gc.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: David Wang <planetbeing@gmail.com> |
  16. | Dmitry Stogov <dmitry@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #ifndef ZEND_GC_H
  20. #define ZEND_GC_H
  21. BEGIN_EXTERN_C()
  22. typedef struct _zend_gc_status {
  23. uint32_t runs;
  24. uint32_t collected;
  25. uint32_t threshold;
  26. uint32_t num_roots;
  27. } zend_gc_status;
  28. ZEND_API extern int (*gc_collect_cycles)(void);
  29. ZEND_API void ZEND_FASTCALL gc_possible_root(zend_refcounted *ref);
  30. ZEND_API void ZEND_FASTCALL gc_remove_from_buffer(zend_refcounted *ref);
  31. /* enable/disable automatic start of GC collection */
  32. ZEND_API zend_bool gc_enable(zend_bool enable);
  33. ZEND_API zend_bool gc_enabled(void);
  34. /* enable/disable possible root additions */
  35. ZEND_API zend_bool gc_protect(zend_bool protect);
  36. ZEND_API zend_bool gc_protected(void);
  37. /* The default implementation of the gc_collect_cycles callback. */
  38. ZEND_API int zend_gc_collect_cycles(void);
  39. ZEND_API void zend_gc_get_status(zend_gc_status *status);
  40. void gc_globals_ctor(void);
  41. void gc_globals_dtor(void);
  42. void gc_reset(void);
  43. END_EXTERN_C()
  44. #define GC_REMOVE_FROM_BUFFER(p) do { \
  45. zend_refcounted *_p = (zend_refcounted*)(p); \
  46. if (GC_TYPE_INFO(_p) & GC_INFO_MASK) { \
  47. gc_remove_from_buffer(_p); \
  48. } \
  49. } while (0)
  50. #define GC_MAY_LEAK(ref) \
  51. ((GC_TYPE_INFO(ref) & \
  52. (GC_INFO_MASK | (GC_COLLECTABLE << GC_FLAGS_SHIFT))) == \
  53. (GC_COLLECTABLE << GC_FLAGS_SHIFT))
  54. static zend_always_inline void gc_check_possible_root(zend_refcounted *ref)
  55. {
  56. if (GC_TYPE_INFO(ref) == IS_REFERENCE) {
  57. zval *zv = &((zend_reference*)ref)->val;
  58. if (!Z_REFCOUNTED_P(zv)) {
  59. return;
  60. }
  61. ref = Z_COUNTED_P(zv);
  62. }
  63. if (UNEXPECTED(GC_MAY_LEAK(ref))) {
  64. gc_possible_root(ref);
  65. }
  66. }
  67. #endif /* ZEND_GC_H */
  68. /*
  69. * Local variables:
  70. * tab-width: 4
  71. * c-basic-offset: 4
  72. * indent-tabs-mode: t
  73. * End:
  74. * vim600: sw=4 ts=4 fdm=marker
  75. * vim<600: sw=4 ts=4
  76. */