2
0

gc.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef AFUN_GC_H
  2. #define AFUN_GC_H
  3. #include "aFuntool.h"
  4. #include "aFunCoreExport.h"
  5. #include "queue"
  6. namespace aFuncore {
  7. typedef unsigned GcCount;
  8. class AFUN_CORE_EXPORT GcObjectBase {
  9. public:
  10. GcObjectBase(const GcObjectBase &) = delete;
  11. GcObjectBase &operator=(const GcObjectBase &) = delete;
  12. inline void addReference();
  13. inline void delReference();
  14. inline void setClear(bool clear=false);
  15. inline void setReachable(bool is_reference=false);
  16. protected:
  17. inline GcObjectBase();
  18. virtual ~GcObjectBase() = default;
  19. private:
  20. bool not_clear; // 不清除
  21. bool reachable; // 可达标记 [同时标识已迭代]
  22. GcCount reference; // 引用计数
  23. };
  24. class AFUN_CORE_EXPORT GcList {
  25. public :
  26. size_t add(GcObjectBase *obj);
  27. GcObjectBase *pop();
  28. [[nodiscard]] inline size_t getSize() const;
  29. [[nodiscard]] inline size_t isEmpty() const;
  30. private:
  31. std::queue<GcObjectBase *> queue;
  32. };
  33. };
  34. #include "gc.inline.h"
  35. #include "gc.template.h"
  36. #endif //AFUN_GC_H