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
|
@ -10,6 +10,7 @@
|
|||
#include <srs_core.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// The resource managed by ISrsResourceManager.
|
||||
class ISrsResource
|
||||
|
@ -20,6 +21,7 @@ public:
|
|||
public:
|
||||
// Get the context id of connection.
|
||||
virtual const SrsContextId& get_id() = 0;
|
||||
public:
|
||||
// The resource description, optional.
|
||||
virtual std::string desc();
|
||||
};
|
||||
|
@ -46,5 +48,49 @@ public:
|
|||
virtual std::string remote_ip() = 0;
|
||||
};
|
||||
|
||||
// Lazy-sweep resource, never sweep util all wrappers are freed.
|
||||
// See https://github.com/ossrs/srs/issues/3176#lazy-sweep
|
||||
class ISrsLazyResource : public ISrsResource
|
||||
{
|
||||
private:
|
||||
// The reference count of resource, 0 is no wrapper and safe to sweep.
|
||||
int32_t gc_ref_;
|
||||
// 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.
|
||||
ISrsResource* gc_creator_wrapper_;
|
||||
// All available wrappers.
|
||||
std::vector<ISrsResource*> gc_wrappers_;
|
||||
public:
|
||||
ISrsLazyResource();
|
||||
virtual ~ISrsLazyResource();
|
||||
public:
|
||||
// For wrapper to use this resource.
|
||||
virtual ISrsLazyResource* gc_use(ISrsResource* wrapper);
|
||||
// For wrapper to dispose this resource.
|
||||
virtual ISrsLazyResource* gc_dispose(ISrsResource* wrapper);
|
||||
// The current reference count of resource.
|
||||
virtual int32_t gc_ref();
|
||||
public:
|
||||
// Set the creator wrapper, from which resource clone wrapper.
|
||||
virtual void gc_set_creator_wrapper(ISrsResource* wrapper);
|
||||
// Get the first available wrapper. NULL if the creator wrapper disposed.
|
||||
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.
|
||||
// See https://github.com/ossrs/srs/issues/3176#lazy-sweep
|
||||
class ISrsLazyGc
|
||||
{
|
||||
public:
|
||||
ISrsLazyGc();
|
||||
virtual ~ISrsLazyGc();
|
||||
public:
|
||||
// Remove then free the specified resource.
|
||||
virtual void remove(ISrsLazyResource* c) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue