mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Kernel: Support lazy sweeping simple GC. v5.0.69
This commit is contained in:
parent
4b7d9587f4
commit
927dd473eb
6 changed files with 221 additions and 3 deletions
|
@ -6,6 +6,9 @@
|
|||
|
||||
#include <srs_protocol_conn.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
ISrsResource::ISrsResource()
|
||||
{
|
||||
}
|
||||
|
@ -35,3 +38,64 @@ ISrsConnection::~ISrsConnection()
|
|||
{
|
||||
}
|
||||
|
||||
ISrsLazyResource::ISrsLazyResource()
|
||||
{
|
||||
gc_ref_ = 0;
|
||||
gc_creator_wrapper_ = NULL;
|
||||
}
|
||||
|
||||
ISrsLazyResource::~ISrsLazyResource()
|
||||
{
|
||||
}
|
||||
|
||||
ISrsLazyResource* ISrsLazyResource::gc_use(ISrsResource* wrapper)
|
||||
{
|
||||
srs_assert(wrapper);
|
||||
if (std::find(gc_wrappers_.begin(), gc_wrappers_.end(), wrapper) == gc_wrappers_.end()) {
|
||||
gc_wrappers_.push_back(wrapper);
|
||||
}
|
||||
|
||||
gc_ref_++;
|
||||
return this;
|
||||
}
|
||||
|
||||
ISrsLazyResource* ISrsLazyResource::gc_dispose(ISrsResource* wrapper)
|
||||
{
|
||||
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_--;
|
||||
return this;
|
||||
}
|
||||
|
||||
int32_t ISrsLazyResource::gc_ref()
|
||||
{
|
||||
return gc_ref_;
|
||||
}
|
||||
|
||||
void ISrsLazyResource::gc_set_creator_wrapper(ISrsResource* wrapper)
|
||||
{
|
||||
gc_creator_wrapper_ = wrapper;
|
||||
}
|
||||
|
||||
ISrsResource* ISrsLazyResource::gc_creator_wrapper()
|
||||
{
|
||||
return gc_creator_wrapper_;
|
||||
}
|
||||
|
||||
ISrsResource* ISrsLazyResource::gc_available_wrapper()
|
||||
{
|
||||
return gc_wrappers_.empty() ? NULL : gc_wrappers_.front();
|
||||
}
|
||||
|
||||
ISrsLazyGc::ISrsLazyGc()
|
||||
{
|
||||
}
|
||||
|
||||
ISrsLazyGc::~ISrsLazyGc()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue