From d4ce877407f0460417b8b0dd86047cc99ae4504a Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 4 Oct 2022 20:47:49 +0800 Subject: [PATCH] Kernel: Refine lazy sweep resource. --- trunk/src/app/srs_app_conn.cpp | 2 +- trunk/src/app/srs_app_conn.hpp | 14 +++++++------- trunk/src/protocol/srs_protocol_conn.cpp | 16 ++++++++-------- trunk/src/protocol/srs_protocol_conn.hpp | 12 ++++++------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/trunk/src/app/srs_app_conn.cpp b/trunk/src/app/srs_app_conn.cpp index afec3d097..ad0708283 100644 --- a/trunk/src/app/srs_app_conn.cpp +++ b/trunk/src/app/srs_app_conn.cpp @@ -420,7 +420,7 @@ srs_error_t SrsSweepGc::start() return err; } -void SrsSweepGc::remove(ISrsLazyResource* c) +void SrsSweepGc::remove(SrsLazyObject* c) { // TODO: FIXME: MUST lazy sweep. srs_freep(c); diff --git a/trunk/src/app/srs_app_conn.hpp b/trunk/src/app/srs_app_conn.hpp index a8d0b87c6..cb596852c 100644 --- a/trunk/src/app/srs_app_conn.hpp +++ b/trunk/src/app/srs_app_conn.hpp @@ -132,7 +132,7 @@ public: virtual ~SrsSweepGc(); public: virtual srs_error_t start(); - virtual void remove(ISrsLazyResource* c); + virtual void remove(SrsLazyObject* c); }; extern ISrsLazyGc* _srs_gc; @@ -140,14 +140,14 @@ extern ISrsLazyGc* _srs_gc; // A wrapper template for lazy-sweep resource. // See https://github.com/ossrs/srs/issues/3176#lazy-sweep template -class SrsLazyResourceWrapper : public ISrsResource +class SrsLazyObjectWrapper : public ISrsResource { private: T* resource_; ISrsResource* wrapper_; bool is_root_; public: - SrsLazyResourceWrapper(T* resource = NULL, ISrsResource* wrapper = NULL) { + SrsLazyObjectWrapper(T* resource = NULL, ISrsResource* wrapper = NULL) { wrapper_ = wrapper ? wrapper : this; resource_ = resource ? resource : new T(); resource_->gc_use(wrapper_); @@ -157,7 +157,7 @@ public: resource_->gc_set_creator_wrapper(wrapper_); } } - virtual ~SrsLazyResourceWrapper() { + virtual ~SrsLazyObjectWrapper() { resource_->gc_dispose(wrapper_); if (is_root_) { @@ -169,8 +169,8 @@ public: } } public: - SrsLazyResourceWrapper* copy() { - return new SrsLazyResourceWrapper(resource_); + SrsLazyObjectWrapper* copy() { + return new SrsLazyObjectWrapper(resource_); } T* resource() { return resource_; @@ -189,7 +189,7 @@ public: // See https://github.com/ossrs/srs/issues/3176#lazy-sweep #define SRS_LAZY_WRAPPER_GENERATOR(Resource, IWrapper, IResource) \ private: \ - SrsLazyResourceWrapper impl_; \ + SrsLazyObjectWrapper impl_; \ public: \ Resource##Wrapper(Resource* resource = NULL) : impl_(resource, this) { \ } \ diff --git a/trunk/src/protocol/srs_protocol_conn.cpp b/trunk/src/protocol/srs_protocol_conn.cpp index 8ebaffb72..9c3ed3dd3 100644 --- a/trunk/src/protocol/srs_protocol_conn.cpp +++ b/trunk/src/protocol/srs_protocol_conn.cpp @@ -38,17 +38,17 @@ ISrsConnection::~ISrsConnection() { } -ISrsLazyResource::ISrsLazyResource() +SrsLazyObject::SrsLazyObject() { gc_ref_ = 0; gc_creator_wrapper_ = NULL; } -ISrsLazyResource::~ISrsLazyResource() +SrsLazyObject::~SrsLazyObject() { } -ISrsLazyResource* ISrsLazyResource::gc_use(ISrsResource* wrapper) +SrsLazyObject* SrsLazyObject::gc_use(ISrsResource* wrapper) { srs_assert(wrapper); if (std::find(gc_wrappers_.begin(), gc_wrappers_.end(), wrapper) == gc_wrappers_.end()) { @@ -59,7 +59,7 @@ ISrsLazyResource* ISrsLazyResource::gc_use(ISrsResource* wrapper) return this; } -ISrsLazyResource* ISrsLazyResource::gc_dispose(ISrsResource* wrapper) +SrsLazyObject* SrsLazyObject::gc_dispose(ISrsResource* wrapper) { srs_assert(wrapper); vector::iterator it = std::find(gc_wrappers_.begin(), gc_wrappers_.end(), wrapper); @@ -71,22 +71,22 @@ ISrsLazyResource* ISrsLazyResource::gc_dispose(ISrsResource* wrapper) return this; } -int32_t ISrsLazyResource::gc_ref() +int32_t SrsLazyObject::gc_ref() { return gc_ref_; } -void ISrsLazyResource::gc_set_creator_wrapper(ISrsResource* wrapper) +void SrsLazyObject::gc_set_creator_wrapper(ISrsResource* wrapper) { gc_creator_wrapper_ = wrapper; } -ISrsResource* ISrsLazyResource::gc_creator_wrapper() +ISrsResource* SrsLazyObject::gc_creator_wrapper() { return gc_creator_wrapper_; } -ISrsResource* ISrsLazyResource::gc_available_wrapper() +ISrsResource* SrsLazyObject::gc_available_wrapper() { return gc_wrappers_.empty() ? NULL : gc_wrappers_.front(); } diff --git a/trunk/src/protocol/srs_protocol_conn.hpp b/trunk/src/protocol/srs_protocol_conn.hpp index 35fb37882..dca32d679 100644 --- a/trunk/src/protocol/srs_protocol_conn.hpp +++ b/trunk/src/protocol/srs_protocol_conn.hpp @@ -50,7 +50,7 @@ public: // Lazy-sweep resource, never sweep util all wrappers are freed. // See https://github.com/ossrs/srs/issues/3176#lazy-sweep -class ISrsLazyResource : public ISrsResource +class SrsLazyObject { private: // The reference count of resource, 0 is no wrapper and safe to sweep. @@ -61,13 +61,13 @@ private: // All available wrappers. std::vector gc_wrappers_; public: - ISrsLazyResource(); - virtual ~ISrsLazyResource(); + SrsLazyObject(); + virtual ~SrsLazyObject(); public: // For wrapper to use this resource. - virtual ISrsLazyResource* gc_use(ISrsResource* wrapper); + virtual SrsLazyObject* gc_use(ISrsResource* wrapper); // For wrapper to dispose this resource. - virtual ISrsLazyResource* gc_dispose(ISrsResource* wrapper); + virtual SrsLazyObject* gc_dispose(ISrsResource* wrapper); // The current reference count of resource. virtual int32_t gc_ref(); public: @@ -89,7 +89,7 @@ public: virtual ~ISrsLazyGc(); public: // Remove then free the specified resource. - virtual void remove(ISrsLazyResource* c) = 0; + virtual void remove(SrsLazyObject* c) = 0; }; #endif