2
0

object.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef AFUN_OBJECT_H
  2. #define AFUN_OBJECT_H
  3. #include <queue>
  4. #include <list>
  5. #include "aFuntool.h"
  6. #include "aFunCoreExport.h"
  7. namespace aFuncore {
  8. typedef unsigned GcCount;
  9. class Inter;
  10. class Environment;
  11. class AFUN_CORE_EXPORT Object {
  12. public:
  13. Object(std::string type_, Inter &inter);
  14. Object(std::string type_, Environment &env_);
  15. virtual ~Object();
  16. Object(const Object &) = delete;
  17. Object &operator=(const Object &) = delete;
  18. AFUN_INLINE void addReference();
  19. AFUN_INLINE void delReference();
  20. [[nodiscard]] AFUN_INLINE GcCount getReference() const;
  21. AFUN_INLINE void setClear(bool clear=false);
  22. AFUN_STATIC void checkReachable(std::list<Object *> &list);
  23. AFUN_STATIC void setReachable(std::list<Object *> &list, std::queue<Object *> &des, std::queue<Object *> &del);
  24. AFUN_STATIC void destructUnreachable(std::queue<Object *> &des, Inter &gc_inter);
  25. AFUN_STATIC void deleteUnreachable(std::queue<Object *> &del);
  26. AFUN_STATIC void destructAll(std::list<Object *> &list, Inter &gc_inter);
  27. AFUN_STATIC void deleteAll(std::list<Object *> &list);
  28. protected:
  29. Environment &env;
  30. const std::string type; // 标识 Object 的字符串
  31. std::mutex lock;
  32. virtual void destruct(Inter &gc_inter);
  33. virtual void linkObject(std::queue<Object *> &queue);
  34. private:
  35. bool done_destruct;
  36. bool not_clear; // 不清除
  37. bool reachable; // 可达标记 [同时标识已迭代]
  38. GcCount reference; // 引用计数
  39. };
  40. };
  41. #include "object.inline.h"
  42. #endif //AFUN_OBJECT_H