mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
GC: Eliminate unused code. v5.0.84
This commit is contained in:
parent
7d9dc69ae1
commit
ef0aefd546
8 changed files with 20 additions and 43 deletions
|
@ -406,21 +406,21 @@ void SrsResourceManager::dispose(ISrsResource* c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSweepGc::SrsSweepGc()
|
SrsLazySweepGc::SrsLazySweepGc()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSweepGc::~SrsSweepGc()
|
SrsLazySweepGc::~SrsLazySweepGc()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsSweepGc::start()
|
srs_error_t SrsLazySweepGc::start()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsSweepGc::remove(SrsLazyObject* c)
|
void SrsLazySweepGc::remove(SrsLazyObject* c)
|
||||||
{
|
{
|
||||||
// TODO: FIXME: MUST lazy sweep.
|
// TODO: FIXME: MUST lazy sweep.
|
||||||
srs_freep(c);
|
srs_freep(c);
|
||||||
|
|
|
@ -125,11 +125,11 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
// A simple lazy-sweep GC, just wait for a long time to delete the disposable resources.
|
// A simple lazy-sweep GC, just wait for a long time to delete the disposable resources.
|
||||||
class SrsSweepGc : public ISrsLazyGc
|
class SrsLazySweepGc : public ISrsLazyGc
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsSweepGc();
|
SrsLazySweepGc();
|
||||||
virtual ~SrsSweepGc();
|
virtual ~SrsLazySweepGc();
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t start();
|
virtual srs_error_t start();
|
||||||
virtual void remove(SrsLazyObject* c);
|
virtual void remove(SrsLazyObject* c);
|
||||||
|
@ -144,21 +144,19 @@ class SrsLazyObjectWrapper : public ISrsResource
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
T* resource_;
|
T* resource_;
|
||||||
ISrsResource* wrapper_;
|
|
||||||
bool is_root_;
|
bool is_root_;
|
||||||
public:
|
public:
|
||||||
SrsLazyObjectWrapper(T* resource = NULL, ISrsResource* wrapper = NULL) {
|
SrsLazyObjectWrapper(T* resource = NULL, ISrsResource* wrapper = NULL) {
|
||||||
wrapper_ = wrapper ? wrapper : this;
|
|
||||||
resource_ = resource ? resource : new T();
|
resource_ = resource ? resource : new T();
|
||||||
resource_->gc_use(wrapper_);
|
resource_->gc_use();
|
||||||
|
|
||||||
is_root_ = !resource;
|
is_root_ = !resource;
|
||||||
if (!resource) {
|
if (!resource) {
|
||||||
resource_->gc_set_creator_wrapper(wrapper_);
|
resource_->gc_set_creator_wrapper(wrapper ? wrapper : this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual ~SrsLazyObjectWrapper() {
|
virtual ~SrsLazyObjectWrapper() {
|
||||||
resource_->gc_dispose(wrapper_);
|
resource_->gc_dispose();
|
||||||
|
|
||||||
if (is_root_) {
|
if (is_root_) {
|
||||||
resource_->gc_set_creator_wrapper(NULL);
|
resource_->gc_set_creator_wrapper(NULL);
|
||||||
|
|
|
@ -366,7 +366,7 @@ srs_error_t SrsLazyGbSession::drive_state()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, we're able to query session by ssrc, for media packets.
|
// Now, we're able to query session by ssrc, for media packets.
|
||||||
SrsLazyGbSessionWrapper* wrapper = dynamic_cast<SrsLazyGbSessionWrapper*>(gc_available_wrapper());
|
SrsLazyGbSessionWrapper* wrapper = dynamic_cast<SrsLazyGbSessionWrapper*>(gc_creator_wrapper());
|
||||||
srs_assert(wrapper); // It MUST never be NULL, because this method is in the cycle of coroutine.
|
srs_assert(wrapper); // It MUST never be NULL, because this method is in the cycle of coroutine.
|
||||||
_srs_gb_manager->add_with_fast_id(ssrc, wrapper);
|
_srs_gb_manager->add_with_fast_id(ssrc, wrapper);
|
||||||
}
|
}
|
||||||
|
@ -998,7 +998,7 @@ srs_error_t SrsLazyGbSipTcpConn::bind_session(SrsSipMessage* msg, SrsLazyGbSessi
|
||||||
if (msg->type_ != HTTP_REQUEST || msg->method_ != HTTP_REGISTER) return err;
|
if (msg->type_ != HTTP_REQUEST || msg->method_ != HTTP_REGISTER) return err;
|
||||||
|
|
||||||
// The lazy-sweep wrapper for this resource.
|
// The lazy-sweep wrapper for this resource.
|
||||||
SrsLazyGbSipTcpConnWrapper* wrapper = dynamic_cast<SrsLazyGbSipTcpConnWrapper*>(gc_available_wrapper());
|
SrsLazyGbSipTcpConnWrapper* wrapper = dynamic_cast<SrsLazyGbSipTcpConnWrapper*>(gc_creator_wrapper());
|
||||||
srs_assert(wrapper); // It MUST never be NULL, because this method is in the cycle of coroutine of receiver.
|
srs_assert(wrapper); // It MUST never be NULL, because this method is in the cycle of coroutine of receiver.
|
||||||
|
|
||||||
// Find exists session for register, might be created by another object and still alive.
|
// Find exists session for register, might be created by another object and still alive.
|
||||||
|
@ -1480,7 +1480,7 @@ srs_error_t SrsLazyGbMediaTcpConn::bind_session(uint32_t ssrc, SrsLazyGbSessionW
|
||||||
if (!ssrc) return err;
|
if (!ssrc) return err;
|
||||||
|
|
||||||
// The lazy-sweep wrapper for this resource.
|
// The lazy-sweep wrapper for this resource.
|
||||||
SrsLazyGbMediaTcpConnWrapper* wrapper = dynamic_cast<SrsLazyGbMediaTcpConnWrapper*>(gc_available_wrapper());
|
SrsLazyGbMediaTcpConnWrapper* wrapper = dynamic_cast<SrsLazyGbMediaTcpConnWrapper*>(gc_creator_wrapper());
|
||||||
srs_assert(wrapper); // It MUST never be NULL, because this method is in the cycle of coroutine.
|
srs_assert(wrapper); // It MUST never be NULL, because this method is in the cycle of coroutine.
|
||||||
|
|
||||||
// Find exists session for register, might be created by another object and still alive.
|
// Find exists session for register, might be created by another object and still alive.
|
||||||
|
|
|
@ -1348,7 +1348,7 @@ srs_error_t SrsServerAdapter::run(SrsWaitGroup* wg)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SrsSweepGc* gc = dynamic_cast<SrsSweepGc*>(_srs_gc);
|
SrsLazySweepGc* gc = dynamic_cast<SrsLazySweepGc*>(_srs_gc);
|
||||||
if ((err = gc->start()) != srs_success) {
|
if ((err = gc->start()) != srs_success) {
|
||||||
return srs_error_wrap(err, "start gc");
|
return srs_error_wrap(err, "start gc");
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,7 +336,7 @@ srs_error_t srs_global_initialize()
|
||||||
#ifdef SRS_GB28181
|
#ifdef SRS_GB28181
|
||||||
_srs_gb_manager = new SrsResourceManager("GB", true);
|
_srs_gb_manager = new SrsResourceManager("GB", true);
|
||||||
#endif
|
#endif
|
||||||
_srs_gc = new SrsSweepGc();
|
_srs_gc = new SrsLazySweepGc();
|
||||||
|
|
||||||
// Initialize global pps, which depends on _srs_clock
|
// Initialize global pps, which depends on _srs_clock
|
||||||
_srs_pps_ids = new SrsPps();
|
_srs_pps_ids = new SrsPps();
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 5
|
#define VERSION_MAJOR 5
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 83
|
#define VERSION_REVISION 84
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -50,25 +50,14 @@ SrsLazyObject::~SrsLazyObject()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsLazyObject* SrsLazyObject::gc_use(ISrsResource* wrapper)
|
SrsLazyObject* SrsLazyObject::gc_use()
|
||||||
{
|
{
|
||||||
srs_assert(wrapper);
|
|
||||||
if (std::find(gc_wrappers_.begin(), gc_wrappers_.end(), wrapper) == gc_wrappers_.end()) {
|
|
||||||
gc_wrappers_.push_back(wrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
gc_ref_++;
|
gc_ref_++;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsLazyObject* SrsLazyObject::gc_dispose(ISrsResource* wrapper)
|
SrsLazyObject* SrsLazyObject::gc_dispose()
|
||||||
{
|
{
|
||||||
srs_assert(wrapper);
|
|
||||||
vector<ISrsResource*>::iterator it = std::find(gc_wrappers_.begin(), gc_wrappers_.end(), wrapper);
|
|
||||||
if (it != gc_wrappers_.end()) {
|
|
||||||
it = gc_wrappers_.erase(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
gc_ref_--;
|
gc_ref_--;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -88,11 +77,6 @@ ISrsResource* SrsLazyObject::gc_creator_wrapper()
|
||||||
return gc_creator_wrapper_;
|
return gc_creator_wrapper_;
|
||||||
}
|
}
|
||||||
|
|
||||||
ISrsResource* SrsLazyObject::gc_available_wrapper()
|
|
||||||
{
|
|
||||||
return gc_wrappers_.empty() ? NULL : gc_wrappers_.front();
|
|
||||||
}
|
|
||||||
|
|
||||||
ISrsLazyGc::ISrsLazyGc()
|
ISrsLazyGc::ISrsLazyGc()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,16 +58,14 @@ private:
|
||||||
// The creator wrapper, which created this resource. Note that it might be disposed and the pointer is NULL, so be
|
// The creator wrapper, which created this resource. Note that it might be disposed and the pointer is NULL, so be
|
||||||
// careful and make sure to check it before use it.
|
// careful and make sure to check it before use it.
|
||||||
ISrsResource* gc_creator_wrapper_;
|
ISrsResource* gc_creator_wrapper_;
|
||||||
// All available wrappers.
|
|
||||||
std::vector<ISrsResource*> gc_wrappers_;
|
|
||||||
public:
|
public:
|
||||||
SrsLazyObject();
|
SrsLazyObject();
|
||||||
virtual ~SrsLazyObject();
|
virtual ~SrsLazyObject();
|
||||||
public:
|
public:
|
||||||
// For wrapper to use this resource.
|
// For wrapper to use this resource.
|
||||||
virtual SrsLazyObject* gc_use(ISrsResource* wrapper);
|
virtual SrsLazyObject* gc_use();
|
||||||
// For wrapper to dispose this resource.
|
// For wrapper to dispose this resource.
|
||||||
virtual SrsLazyObject* gc_dispose(ISrsResource* wrapper);
|
virtual SrsLazyObject* gc_dispose();
|
||||||
// The current reference count of resource.
|
// The current reference count of resource.
|
||||||
virtual int32_t gc_ref();
|
virtual int32_t gc_ref();
|
||||||
public:
|
public:
|
||||||
|
@ -75,9 +73,6 @@ public:
|
||||||
virtual void gc_set_creator_wrapper(ISrsResource* wrapper);
|
virtual void gc_set_creator_wrapper(ISrsResource* wrapper);
|
||||||
// Get the first available wrapper. NULL if the creator wrapper disposed.
|
// Get the first available wrapper. NULL if the creator wrapper disposed.
|
||||||
virtual ISrsResource* gc_creator_wrapper();
|
virtual ISrsResource* gc_creator_wrapper();
|
||||||
// Get the first available wrapper. NULL if all wrappers disposed.
|
|
||||||
// It should be equal to the gc_creator_wrapper() if creator wrapper not disposed.
|
|
||||||
virtual ISrsResource* gc_available_wrapper();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// The lazy-sweep GC, wait for a long time to dispose resource even when resource is disposable.
|
// The lazy-sweep GC, wait for a long time to dispose resource even when resource is disposable.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue